ZQuest Classic Coverage Report


Directory: src/
File: src/zq/zquest.cpp
Date: 2025-01-10 07:54:00
Exec Total Coverage
Lines: 2351 15252 15.4%
Functions: 50 744 6.7%
Branches: 1446 11430 12.7%

Line Branch Exec Source
1 #include "allegro/gui.h"
2 #include "base/files.h"
3 #define MIDI_TRACK_BUFFER_SIZE 50
4
5 #include <memory>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <cstring>
9 #include <sstream>
10 #include <ctype.h>
11 #include <assert.h>
12 #include <time.h>
13 #include <vector>
14 #include <filesystem>
15 #include <base/new_menu.h>
16
17 #include "dialog/info_lister.h"
18 #ifdef __APPLE__
19 // malloc.h is deprecated, but malloc also lives in stdlib
20 #include <stdlib.h>
21 #else
22 #include <malloc.h>
23 #endif
24
25 #include "zalleg/zalleg.h"
26 #include "base/qrs.h"
27 #include "base/dmap.h"
28 #include "base/msgstr.h"
29 #include "base/packfile.h"
30 #include "base/cpool.h"
31 #include "base/autocombo.h"
32 #include "base/render.h"
33 #include "base/version.h"
34 #include "zq/autocombo/autopattern_base.h"
35 #include "zq/autocombo/pattern_basic.h"
36 #include "zq/autocombo/pattern_flatmtn.h"
37 #include "zq/autocombo/pattern_fence.h"
38 #include "zq/autocombo/pattern_cakemtn.h"
39 #include "zq/autocombo/pattern_relational.h"
40 #include "zq/autocombo/pattern_dungeoncarve.h"
41 #include "zq/autocombo/pattern_dormtn.h"
42 #include "zq/autocombo/pattern_tiling.h"
43 #include "zq/autocombo/pattern_replace.h"
44 #include "zq/autocombo/pattern_denseforest.h"
45 #include "zq/autocombo/pattern_extend.h"
46 #include "zq/render_hotkeys.h"
47 #include "zq/render_minimap.h"
48 #include "zq/render_tooltip.h"
49 #include "base/misctypes.h"
50 #include "parser/Compiler.h"
51 #include "base/zc_alleg.h"
52 #include "particles.h"
53 #include "dialog/combopool.h"
54 #include "dialog/alert.h"
55 #include "dialog/alertfunc.h"
56 #include "zq/gui/edit_autocombo.h"
57
58 9 particle_list particles;
59 9 void setZScriptVersion(int32_t) { } //bleh...
60
61 #include <al5_img.h>
62 #include <loadpng.h>
63 #include <fmt/format.h>
64
65 #include "dialog/cheat_codes.h"
66 #include "dialog/set_password.h"
67 #include "dialog/foodlg.h"
68 #include "dialog/quest_rules.h"
69 #include "dialog/script_rules.h"
70 #include "dialog/headerdlg.h"
71 #include "dialog/ffc_editor.h"
72 #include "dialog/screen_data.h"
73 #include "dialog/edit_dmap.h"
74 #include "dialog/compilezscript.h"
75 #include "dialog/screen_enemies.h"
76 #include "dialog/enemypattern.h"
77 #include "dialog/sfxdata.h"
78 #include "dialog/mapstyles.h"
79 #include "dialog/externs.h"
80
81 #include "base/gui.h"
82 #include "gui/jwin_a5.h"
83 #include "gui/jwin.h"
84 #include "zc_list_data.h"
85 #include "gui/editbox.h"
86 #include "zq/zq_misc.h"
87 #include "zq/zq_tiles.h" // tile and combo code
88
89 #include "zq/zquest.h"
90 #include "zq/ffasm.h"
91 #include "zq/render.h"
92
93 // the following are used by both zelda.cc and zquest.cc
94 #include "base/zdefs.h"
95 #include "base/qrs.h"
96 #include "tiles.h"
97 #include "base/colors.h"
98 #include "base/qst.h"
99 #include "base/zsys.h"
100 #include "base/zapp.h"
101 #include "play_midi.h"
102 #include "sound/zcmusic.h"
103
104 #include "midi.h"
105 #include "sprite.h"
106 #include "fontsdat.h"
107 #include "base/jwinfsel.h"
108 #include "zq/zq_class.h"
109 #include "subscr.h"
110 #include "zq/zq_subscr.h"
111 #include "zc/ffscript.h"
112 #include "gui/EditboxNew.h"
113 #include "sfx.h"
114 #include "zq/zq_custom.h" // custom items and guys
115 #include "zq/zq_strings.h"
116 #include "zq/questReport.h"
117 #include "zq/ffasmexport.h"
118 #include <fstream>
119 #include "base/module.h"
120 #include "drawing.h"
121 #include "zconsole/ConsoleLogger.h"
122 #include "colorname.h"
123 #include "zq/zq_hotkey.h"
124 #include "zq/package.h"
125 #include "zq/zq_files.h"
126 #include "music_playback.h"
127
128 extern CConsoleLoggerEx parser_console;
129
130 namespace fs = std::filesystem;
131
132 //Windows mmemory tools
133 #ifdef _WIN32
134 #include <windows.h>
135 #include <stdio.h>
136 #include <psapi.h>
137 #pragma comment(lib, "psapi.lib") // Needed to avoid linker issues. -Z
138 #endif
139
140 #ifdef __EMSCRIPTEN__
141 #include <emscripten/emscripten.h>
142 #endif
143
144 //SDL_Surface *sdl_screen;
145
146 #if defined(ALLEGRO_WINDOWS)
147 static const char *data_path_name = "win_data_path";
148 static const char *midi_path_name = "win_midi_path";
149 static const char *image_path_name = "win_image_path";
150 static const char *tmusic_path_name = "win_tmusic_path";
151 static const char *last_quest_name = "win_last_quest";
152 static const char *qtname_name = "win_qtname%d";
153 static const char *qtpath_name = "win_qtpath%d";
154 #elif defined(ALLEGRO_LINUX)
155 static const char *data_path_name = "linux_data_path";
156 static const char *midi_path_name = "linux_midi_path";
157 static const char *image_path_name = "linux_image_path";
158 static const char *tmusic_path_name = "linux_tmusic_path";
159 static const char *last_quest_name = "linux_last_quest";
160 static const char *qtname_name = "linux_qtname%d";
161 static const char *qtpath_name = "linux_qtpath%d";
162 #elif defined(__APPLE__)
163 static const char *data_path_name = "macosx_data_path";
164 static const char *midi_path_name = "macosx_midi_path";
165 static const char *image_path_name = "macosx_image_path";
166 static const char *tmusic_path_name = "macosx_tmusic_path";
167 static const char *last_quest_name = "macosx_last_quest";
168 static const char *qtname_name = "macosx_qtname%d";
169 static const char *qtpath_name = "macosx_qtpath%d";
170 #endif
171
172 #include "base/win32.h"
173
174 #include "zq/zq_init.h"
175 #include "zq/zq_doors.h"
176 #include "zq/zq_cset.h"
177 #include "zinfo.h"
178
179 #ifdef _MSC_VER
180 #include <crtdbg.h>
181
182 #endif
183
184 // MSVC fix
185 #if _MSC_VER >= 1900
186 FILE _iob[] = { *stdin, *stdout, *stderr };
187 extern "C" FILE * __cdecl __iob_func(void) { return _iob; }
188 #endif
189
190 extern byte monochrome_console;
191
192 #include "zconsole/ConsoleLogger.h"
193
194 extern CConsoleLoggerEx zscript_coloured_console;
195
196 uint8_t console_is_open = 0;
197 uint8_t __isZQuest = 1; //Shared functionscan reference this. -Z
198 bool is_zq_replay_test = false;
199
200 #include "base/util.h"
201
202 #ifdef __EMSCRIPTEN__
203 #include "base/emscripten_utils.h"
204 #endif
205
206 using namespace util;
207
208 using std::vector;
209 using std::map;
210 using std::stringstream;
211
212 9 FFScript FFCore;
213
214 void load_size_poses();
215 void do_previewtext();
216 bool do_slots(map<string, disassembled_script_data> &scripts, int assign_mode);
217 void do_script_disassembly(map<string, disassembled_script_data>& scripts, bool fromCompile);
218
219 int32_t startdmapxy[6] = {-1000, -1000, -1000, -1000, -1000, -1000};
220 bool cancelgetnum=false;
221
222 int32_t tooltip_timer=0, tooltip_maxtimer=30, tooltip_current_ffc=0;
223 int32_t combobrushoverride=-1;
224 ComboPosition mouse_combo_pos;
225
226 int32_t original_playing_field_offset=0;
227 9 int32_t playing_field_offset=original_playing_field_offset;
228 int32_t passive_subscreen_height=56;
229 int32_t passive_subscreen_offset=0;
230
231 bool disable_saving=false, OverwriteProtection;
232 bool halt=false;
233 bool show_sprites=true;
234 bool show_hitboxes = false;
235 bool zq_ignore_item_ownership = true;
236
237 // Used to find FFC script names
238 vector<string> asffcscripts;
239 vector<string> asglobalscripts;
240 vector<string> asitemscripts;
241 vector<string> asnpcscripts;
242 vector<string> aseweaponscripts;
243 vector<string> aslweaponscripts;
244 vector<string> asplayerscripts;
245 vector<string> asdmapscripts;
246 vector<string> asscreenscripts;
247 vector<string> asitemspritescripts;
248 vector<string> ascomboscripts;
249 vector<string> asgenericscripts;
250 vector<string> assubscreenscripts;
251
252 vector<string> ZQincludePaths;
253
254 int32_t CSET_SIZE = 16;
255 int32_t CSET_SHFT = 4;
256 //editbox_data temp_eb_data;
257 /*
258 #define CSET(x) ((x)<<CSET_SHFT)
259 #define csBOSS 14
260 */
261
262 /*
263 enum { m_block, m_coords, m_flags, m_guy, m_warp, m_misc, m_layers,
264 m_menucount };
265 */
266 void update_combo_cycling();
267 void update_freeform_combos();
268
269 /*
270 #define MAXMICE 14
271 #define MAXARROWS 8
272 #define SHADOW_DEPTH 2
273 */
274 int32_t coord_timer=0, coord_frame=0;
275 int32_t blackout_color, zq_screen_w, zq_screen_h;
276 int32_t draw_mode=0;
277
278 9 size_and_pos minimap;
279 9 size_and_pos real_minimap;
280
281 9 size_and_pos minimap_zoomed;
282 9 size_and_pos real_minimap_zoomed;
283
284 9 size_and_pos map_page_bar[9];
285 int32_t mappage_count = 9;
286
287 9 size_and_pos combolist[MAX_COMBO_COLS];
288 9 size_and_pos combolistscrollers[MAX_COMBO_COLS];
289 int32_t num_combo_cols = MAX_COMBO_COLS;
290
291 static bool zoom_in_btn_disabled;
292 static bool zoom_out_btn_disabled;
293 9 size_and_pos zoominbtn;
294 9 size_and_pos zoomoutbtn;
295 9 size_and_pos compactbtn;
296 9 size_and_pos mainbar;
297
298 9 size_and_pos screrrorpos;
299
300 9 size_and_pos comboaliaslist[MAX_COMBO_COLS];
301 9 size_and_pos comboalias_preview;
302 9 size_and_pos combopool_preview;
303 9 size_and_pos combopool_prevbtn;
304
305 9 size_and_pos combo_merge_btn;
306
307 9 size_and_pos combo_preview;
308 9 size_and_pos combo_preview2;
309 9 size_and_pos combo_preview_text1;
310 9 size_and_pos combo_preview_text2;
311 9 size_and_pos combolist_window;
312 9 size_and_pos drawmode_btn;
313 9 size_and_pos main_panel;
314 9 size_and_pos squares_panel;
315 9 size_and_pos preview_panel;
316 9 size_and_pos layer_panel;
317 9 size_and_pos preview_text;
318
319 9 size_and_pos favorites_window;
320 9 size_and_pos favorites_list;
321 9 size_and_pos favorites_x;
322 9 size_and_pos favorites_infobtn;
323 9 size_and_pos favorites_zoombtn;
324 9 size_and_pos favorites_pgleft;
325 9 size_and_pos favorites_pgright;
326
327 9 size_and_pos commands_window;
328 9 size_and_pos commands_list;
329 9 size_and_pos commands_x;
330 9 size_and_pos commands_infobtn;
331 9 size_and_pos commands_zoombtn;
332 9 size_and_pos commands_txt;
333
334 9 size_and_pos squarepanel_swap_btn;
335 9 size_and_pos squarepanel_up_btn;
336 9 size_and_pos squarepanel_down_btn;
337 9 size_and_pos itemsqr_pos;
338 9 size_and_pos flagsqr_pos;
339 9 size_and_pos stairsqr_pos;
340 9 size_and_pos warparrival_pos;
341 9 size_and_pos warpret_pos[4];
342 9 size_and_pos enemy_prev_pos;
343
344 9 size_and_pos txtoffs_single;
345 9 size_and_pos txtoffs_double_1;
346 9 size_and_pos txtoffs_double_2;
347 int32_t panel_align = 1;
348
349 int32_t command_buttonwidth = 88;
350 int32_t command_buttonheight = 19;
351
352 int32_t layerpanel_buttonwidth = 58;
353 int32_t layerpanel_buttonheight = 16;
354
355 int32_t layerpanel_checkbox_hei = 13;
356 int32_t layerpanel_checkbox_wid = 13;
357
358 int32_t favorite_combos[MAXFAVORITECOMBOS];
359 byte favorite_combo_modes[MAXFAVORITECOMBOS];
360 bool ShowFavoriteComboModes;
361 byte FavoriteComboPage;
362
363 char comboprev_buf[512] = {0};
364 char comboprev_buf2[512] = {0};
365 FONT* txfont;
366
367 const char *roomtype_string[MAXROOMTYPES] =
368 {
369 "(None)","Special Item","Pay for Info","Secret Money","Gamble",
370 "Door Repair","Red Potion or Heart Container","Feed the Goriya","Triforce Check",
371 "Potion Shop","Shop","More Bombs","Leave Money or Life","10 Rupees",
372 "3-Stair Warp","Ganon","Zelda", "-<item pond>", "1/2 Magic Upgrade", "Learn Slash", "More Arrows","Take One Item"
373 };
374
375 const char *catchall_string[MAXROOMTYPES] =
376 {
377 "Generic Catchall","Special Item","Info Type","Amount","Generic Catchall","Repair Fee","Generic Catchall","Generic Catchall","Generic Catchall","Shop Type",
378 "Shop Type","Price","Price","Generic Catchall","Warp Ring","Generic Catchall","Generic Catchall", "Generic Catchall", "Generic Catchall",
379 "Generic Catchall", "Price","Shop Type","Bottle Shop Type"
380 };
381
382 #define MAXPOOLCOMBOS MAXFAVORITECOMBOS
383
384 struct cmbdat_pair
385 {
386 int32_t data;
387 byte cset;
388 11340 cmbdat_pair() { clear(); }
389 18900 void clear()
390 {
391 18900 data = -1;
392 18900 cset = 0;
393 18900 }
394 bool valid() const
395 {
396 return data > -1;
397 }
398 };
399 bool pool_dirty=true;
400 9 cmbdat_pair pool_combos[MAXPOOLCOMBOS];
401 static std::vector<byte> pool;
402
403 bool pool_valid()
404 {
405 if(pool_dirty)
406 {
407 pool.clear();
408 for(auto q = 0; q < MAXPOOLCOMBOS; ++q)
409 {
410 if(pool_combos[q].valid())
411 pool.push_back(q);
412 }
413 pool_dirty = false;
414 }
415 return pool.size() > 0;
416 }
417 cmbdat_pair const& get_pool_combo()
418 {
419 if(!pool_valid()) return pool_combos[0];
420 auto ind = zc_rand(pool.size()-1);
421 return pool_combos[pool.at(ind)];
422 }
423
424 int32_t mouse_scroll_h;
425
426 // 'mapscreen' refers to the area of the editor where the screen is drawn.
427 int32_t mapscreen_x, mapscreen_y, showedges, showallpanels;
428 // The scale of the entire mapscreen area. This varies based on compact/extended mode.
429 static int mapscreen_screenunit_scale;
430 // Would love to have no limit, but our screen bitmap has too low a resolution at the moment.
431 // The scale of an individual screen being drawn. This is `mapscreen_screenunit_scale / Map.getViewSize()`.
432 static double mapscreen_single_scale;
433 // 4 is roughly the largest value where things render okay. Beyond that, our low bitmap resolution results in tons
434 // of downsampling. Let users go to 16 anyway.
435 static int mapscreen_num_screens_to_draw_max = 16;
436 // The valid layers for the current screen(s).
437 static bool mapscreen_valid_layers[6];
438
439 struct VisibleScreen
440 {
441 int dx, dy;
442 int xoff, yoff;
443 mapscr* scr;
444 int screen;
445 };
446 static std::vector<VisibleScreen> visible_screens;
447 static VisibleScreen* active_visible_screen = nullptr;
448
449 static void set_active_visible_screen(mapscr* scr)
450 {
451 active_visible_screen = nullptr;
452 for (auto& visible_screen : visible_screens)
453 {
454 if (visible_screen.scr == scr)
455 {
456 active_visible_screen = &visible_screen;
457 break;
458 }
459 }
460 }
461
462 static ComboPosition get_mapscreen_mouse_combo_pos()
463 {
464 int startxint = mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
465 int startyint = mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
466 int cx = (gui_mouse_x()-startxint)/(16*mapscreen_single_scale);
467 int cy = (gui_mouse_y()-startyint)/(16*mapscreen_single_scale);
468 return ComboPosition{cx, cy};
469 }
470
471 static void refresh_visible_screens()
472 {
473 int num_screens = Map.getViewSize();
474 int screen_width = mapscreenbmp->w * mapscreen_single_scale;
475 int screen_height = mapscreenbmp->h * mapscreen_single_scale;
476
477 visible_screens.clear();
478 for (int dx = 0; dx < num_screens; dx++)
479 {
480 for (int dy = 0; dy < num_screens; dy++)
481 {
482 int mx = Map.getViewScr()%16 + dx;
483 int my = Map.getViewScr()/16 + dy;
484 if (mx < 0 || mx >= 16 || my < 0 || my >= 9)
485 continue;
486
487 int screen = Map.getViewScr() + dx + dy * 16;
488 if (screen >= MAPSCRS)
489 continue;
490
491 mapscr* scr = Map.Scr(screen);
492 int offx = dx * screen_width;
493 int offy = dy * screen_height;
494 visible_screens.emplace_back(VisibleScreen{dx, dy, offx, offy, scr, screen});
495 }
496 }
497
498 for (int i = 0; i < 6; i++)
499 {
500 mapscreen_valid_layers[i] = false;
501 for (auto& vis_screen : visible_screens)
502 {
503 mapscreen_valid_layers[i] |= vis_screen.scr->layermap[i] > 0;
504 }
505 }
506 }
507
508 int32_t readsize, writesize;
509 bool fake_pack_writing=false;
510
511 int32_t showxypos_x;
512 int32_t showxypos_y;
513 int32_t showxypos_w;
514 int32_t showxypos_h;
515 int32_t showxypos_color;
516 int32_t showxypos_ffc=-1000;
517 bool showxypos_icon=false;
518
519 int32_t showxypos_cursor_x;
520 int32_t showxypos_cursor_y;
521 bool showxypos_cursor_icon=false;
522 int32_t showxypos_cursor_color;
523 bool showxypos_dummy = false;
524
525 bool canfill=true; //to prevent double-filling (which stops undos)
526 int32_t lens_hint_item[MAXITEMS][2]; //aclk, aframe
527 int32_t lens_hint_weapon[MAXWPNS][5]; //aclk, aframe, dir, x, y
528 //int32_t mode, switch_mode, orig_mode;
529 int32_t tempmode=GFX_AUTODETECT;
530 RGB_MAP zq_rgb_table;
531 COLOR_MAP trans_table, trans_table2;
532 MIDI *song=NULL;
533 BITMAP *menu1, *menu3, *mapscreenbmp, *tmp_scr, *screen2, *mouse_bmp[MOUSE_BMP_MAX][4], *mouse_bmp_1x[MOUSE_BMP_MAX][4], *icon_bmp[ICON_BMP_MAX][4], *flag_bmp[16][4], *select_bmp[2], *dmapbmp_small, *dmapbmp_large;
534 BITMAP *arrow_bmp[MAXARROWS],*brushbmp, *brushscreen; //*brushshadowbmp;
535 byte *colordata=NULL, *trashbuf=NULL;
536 itemdata *itemsbuf;
537 wpndata *wpnsbuf;
538 comboclass *combo_class_buf;
539 guydata *guysbuf;
540 item_drop_object item_drop_sets[MAXITEMDROPSETS];
541 9 newcombo curr_combo;
542 PALETTE RAMpal;
543 midi_info Midi_Info;
544 bool zq_showpal=false;
545 bool is_compact = false;
546
547 int pixeldb = 1;
548 int infobg = 1;
549 bool large_merged_combopane = false;
550 bool compact_merged_combopane = true;
551 bool large_zoomed_fav = false;
552 bool compact_zoomed_fav = true;
553 bool large_zoomed_cmd = false;
554 bool compact_zoomed_cmd = true;
555
556 bool compact_square_panels = false;
557 int compact_active_panel = 0;
558
559 int combo_col_scale = 1;
560
561 std::vector<std::shared_ptr<zasm_script>> zasm_scripts;
562 script_data *ffscripts[NUMSCRIPTFFC];
563 script_data *itemscripts[NUMSCRIPTITEM];
564 script_data *guyscripts[NUMSCRIPTGUYS];
565 script_data *lwpnscripts[NUMSCRIPTWEAPONS];
566 script_data *ewpnscripts[NUMSCRIPTWEAPONS];
567 script_data *globalscripts[NUMSCRIPTGLOBAL];
568 script_data *genericscripts[NUMSCRIPTSGENERIC];
569 script_data *playerscripts[NUMSCRIPTHERO];
570 script_data *screenscripts[NUMSCRIPTSCREEN];
571 script_data *dmapscripts[NUMSCRIPTSDMAP];
572 script_data *itemspritescripts[NUMSCRIPTSITEMSPRITE];
573 script_data *comboscripts[NUMSCRIPTSCOMBODATA];
574 script_data *subscreenscripts[NUMSCRIPTSSUBSCREEN];
575
576 extern string zScript;
577 char zScriptBytes[512];
578 char zLastVer[512] = { 0 };
579 SAMPLE customsfxdata[WAV_COUNT];
580 uint8_t customsfxflag[WAV_COUNT>>3];
581 int32_t sfxdat=1;
582
583 int32_t onImport_ComboAlias();
584 int32_t onExport_ComboAlias();
585
586 void set_console_state();
587
588 void clearConsole()
589 {
590 if(!console_is_open) return;
591 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
592 zscript_coloured_console.gotoxy(0,0);
593 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
594 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
595 }
596
597 void initConsole()
598 {
599 if(console_is_open) return;
600 console_is_open = 1;
601 set_console_state();
602 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
603 clearConsole();
604 }
605
606 9 void killConsole()
607 {
608
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!console_is_open) return;
609 console_is_open = 0;
610 set_console_state();
611 zscript_coloured_console.kill();
612 9 }
613
614 int toggleConsole()
615 {
616 console_is_open ? killConsole() : initConsole();
617 zc_set_config("zquest","open_debug_console",console_is_open?1:0);
618 return D_O_K;
619 }
620
621 int showHotkeys()
622 {
623 hotkeys_toggle_display(!hotkeys_is_active());
624 return D_O_K;
625 }
626
627 typedef int32_t (*intF)();
628 typedef struct command_pair
629 {
630 char name[80];
631 int32_t flags;
632 intF command;
633 } command_pair;
634
635 extern map_and_screen map_page[MAX_MAPPAGE_BTNS];
636
637 int32_t do_OpenQuest()
638 {
639 return onOpen();
640 }
641
642 int32_t do_NewQuest()
643 {
644 //clear the panel recent screen buttons to prevent crashes from invalid maps
645 for ( int32_t q = 0; q < 9; q++ )
646 {
647 map_page[q].map = 0;
648 map_page[q].screen = 0;
649 }
650 Map.setCurrMap(0);
651 Map.setCurrScr(0);
652 return onNew();
653 }
654
655 extern int CheckerCol1, CheckerCol2;
656 int32_t alignment_arrow_timer=0;
657 int32_t Flip=0,Combo=0,CSet=2,current_combolist=0,current_comboalist=0,current_cpoollist=0,current_cautolist=0,current_mappage=0;
658 int32_t Flags=0,Flag=0,menutype=(m_block);
659 int MouseScroll = 0, SavePaths = 0, CycleOn = 0, ShowGrid = 0, ShowScreenGrid = 0, GridColor = 15, ShowCurScreenOutline = 1,
660 CmbCursorCol = 15, TilePgCursorCol = 15, CmbPgCursorCol = 15, TTipHLCol = 13,
661 TileProtection = 0, ComboProtection = 0, NoScreenPreview = 0, MMapCursorStyle = 0,
662 LayerDitherBG = -1, LayerDitherSz = 2, RulesetDialog = 0,
663 EnableTooltips = 0, TooltipsHighlight = 0, ShowFFScripts = 0, ShowSquares = 0,
664 ShowFFCs = 0, ShowInfo = 0, skipLayerWarning = 0, WarnOnInitChanged = 0,
665 DisableLPalShortcuts = 1, DisableCompileConsole = 0, numericalFlags = 0,
666 ActiveLayerHighlight = 0, DragCenterOfSquares = 0;
667 uint8_t InvalidBG = 0;
668 bool NoHighlightLayer0 = false;
669 int32_t FlashWarpSquare = -1, FlashWarpClk = 0; // flash the destination warp return when ShowSquares is active
670 uint8_t ViewLayer3BG = 0, ViewLayer2BG = 0;
671 int32_t window_width, window_height;
672 bool ShowFPS = false, SaveDragResize = false, DragAspect = false, SaveWinPos=false;
673 bool allowHideMouse = false;
674 double aspect_ratio = LARGE_H / double(LARGE_W);
675 int window_min_width = 0, window_min_height = 0;
676 int32_t ComboBrush = 0; //show the brush instead of the normal mouse
677 int32_t ComboBrushPause = 0; //temporarily disable the combo brush
678 int32_t FloatBrush = 0; //makes the combo brush float a few pixels up and left
679 int AutoBrush = 0; //Drag to size the brush on the combo panes
680 bool AutoBrushRevert = false; //Revert after placing
681 int LinkedScroll = 0;
682 //complete with shadow
683 int32_t OpenLastQuest = 0; //makes the program reopen the quest that was
684 //open at the time you quit
685 int32_t ShowMisalignments = 0; //makes the program display arrows over combos that are
686 //not aligned with the next screen.
687 int32_t AnimationOn = 0; //animate the combos in zquest?
688 int32_t AutoBackupRetention = 0; //use auto-backup feature? if so, how many backups (1-10) to keep
689 int32_t AutoSaveInterval = 0; //how often a timed autosave is made (not overwriting the current file)
690 int32_t UncompressedAutoSaves = 0; //should timed saves be uncompressed/encrypted?
691 int32_t KeyboardRepeatDelay = 0; //the time in milliseconds after holding down a key that the key starts to repeat
692 int32_t KeyboardRepeatRate = 0; //the time in milliseconds between each repetition of a repeated key
693
694 time_t auto_save_time_start, auto_save_time_current;
695 double auto_save_time_diff = 0;
696 int32_t AutoSaveRetention = 0; //how many autosaves of a quest to keep
697 int32_t ImportMapBias = 0; //tells what has precedence on map importing
698 int32_t BrushWidth=1, BrushHeight=1;
699 bool saved=true;
700 bool __debug=false;
701 int32_t LayerMaskInt[7]={0};
702 int32_t CurrentLayer=0;
703 int32_t DuplicateAction[4]={0};
704 int32_t OnlyCheckNewTilesForDuplicates = 0;
705 int32_t try_recovering_missing_scripts = 0;
706
707 uint8_t PreFillTileEditorPage = 0, PreFillComboEditorPage = 0;
708 int32_t DMapEditorLastMaptileUsed = 0;
709
710 /*
711 , HorizontalDuplicateAction;
712 int32_t VerticalDuplicateAction, BothDuplicateAction;
713 */
714 word msg_count = 0;
715 int32_t LeechUpdate = 0;
716 int32_t LeechUpdateTiles = 0;
717 int32_t SnapshotFormat = 0;
718 byte SnapshotScale = 0;
719
720 byte Color = 0;
721 extern int32_t jwin_pal[jcMAX];
722 int32_t gui_colorset=99;
723
724 static int32_t combo_apos=0; //currently selected combo alias
725 int32_t alias_origin=0;
726 int32_t alias_cset_mod=0;
727
728 static int32_t combo_pool_pos=0; //currently selected combo pool
729 bool weighted_cpool = true;
730 bool cpool_prev_visible = false;
731
732 static int32_t combo_auto_pos=0; //currently selected autocombo
733 byte cauto_height = 1;
734
735 bool trip=false;
736
737 int32_t fill_type=1;
738
739 bool first_save=false;
740 char *filepath,*midipath,*datapath,*imagepath,*tmusicpath,*last_timed_save;
741 string helpstr, zstringshelpstr;
742
743 ZCMUSIC *zcmusic = NULL;
744 ZCMIXER *zcmixer = NULL;
745 int32_t midi_volume = 255;
746 extern int32_t prv_mode;
747 int32_t prv_warp = 0;
748 int32_t prv_twon = 0;
749 int32_t ff_combo = 0;
750
751 int32_t Frameskip = 0, RequestedFPS = 60, zqUseWin32Proc = 1;
752 int32_t zqColorDepth = 8;
753 int32_t joystick_index=0;
754
755 9 void set_last_timed_save(char const* buf)
756 {
757
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 9 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 if(buf && buf[0])
758 {
759 if(buf != last_timed_save)
760 strcpy(last_timed_save, buf);
761 }
762 else
763 {
764 9 last_timed_save[0] = 0;
765 9 buf = nullptr;
766 }
767 9 zc_set_config("zquest","last_timed_save",buf);
768 9 }
769
770 void loadlvlpal(int32_t level);
771 bool get_debug()
772 {
773 return __debug;
774 //return true;
775 }
776
777 void set_debug(bool d)
778 {
779 __debug=d;
780 return;
781 }
782
783 bool handle_quit()
784 {
785 if(onExit()==D_CLOSE)
786 return (exiting_program = true);
787 return false;
788 }
789 bool handle_close_btn_quit()
790 {
791 if(close_button_quit)
792 {
793 close_button_quit=false;
794 return handle_quit();
795 }
796 return false;
797 }
798 // **** Timers ****
799
800 volatile int32_t lastfps=0;
801 volatile int32_t framecnt=0;
802 size_t cpoolbrush_index = 0;
803
804 // quest data
805 zquestheader header;
806 byte midi_flags[MIDIFLAGS_SIZE];
807 byte music_flags[MUSICFLAGS_SIZE];
808 byte *quest_file;
809 int32_t msg_strings_size;
810 zctune *customtunes;
811 //emusic *enhancedMusic;
812 ZCHEATS zcheats;
813 byte use_cheats;
814 byte use_tiles;
815 // Note: may not be null-terminated (must refactor writecolordata to fix).
816 char palnames[MAXLEVELS][17];
817 char zquestdat_sig[52];
818 char qstdat_str[2048];
819
820 int32_t gme_track=0;
821
822 int32_t dlevel; // just here until gamedata is properly done
823
824 10 bool bad_version(int32_t ver)
825 {
826
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(ver < 0x170)
827 return true;
828
829 10 return false;
830 10 }
831
832 // These are for drawing eyeballs correctly in combo_tile.
833 zfix HeroModifiedX()
834 {
835 return gui_mouse_x() - 7;
836 }
837 zfix HeroModifiedY()
838 {
839 return gui_mouse_y() - 7;
840 }
841
842
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu import_250_menu
843 36 {
844
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&DMaps", onImport_DMaps },
845
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Table", onImport_Combos },
846
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Alias", onImport_ComboAlias },
847 };
848
849
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu import_graphics
850 135 {
851
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Palettes", onImport_Pals },
852
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
853
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Tileset (&Full)", onImport_Tiles },
854
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Tile Pack", onImport_Tilepack },
855
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "T&ile Pack to...", onImport_Tilepack_To },
856
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
857
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Set (Range)", onImport_Combos },
858
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo Pack (Full, 1:1)", onImport_Combopack },
859
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo Pack to... (Dest)", onImport_Combopack_To },
860
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
861
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo &Alias Pack", onImport_Comboaliaspack },
862
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo A&lias Pack to...", onImport_Comboaliaspack_To },
863
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
864
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Doorsets", onImport_Doorset },
865 };
866
867
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu import_menu
868 90 {
869
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Enemies", onImport_Guys },
870
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Map", onImport_Map },
871
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&DMaps", onImport_DMaps },
872
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Strings (.tsv)", onImport_StringsTSV },
873
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "String Table (deprecated)", onImport_Msgs },
874
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
875
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Graphics", &import_graphics },
876
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
877
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2.50 (Broken)", &import_250_menu },
878 };
879
880
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu export_250_menu
881 45 {
882
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&DMaps", onExport_DMaps },
883
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Table", onExport_Combos },
884
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Alias", onExport_ComboAlias },
885
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Graphics Pack", onExport_ZGP },
886 };
887
888
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu zq_help_menu
889 27 {
890
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Editor Help", onHelp },
891
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Strings Help", onZstringshelp },
892 };
893
894
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu export_graphics
895 108 {
896
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Palettes", onExport_Pals },
897
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
898
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Tileset (&Full)", onExport_Tiles },
899
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Tile Pack", onExport_Tilepack },
900
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
901
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Set", onExport_Combos },
902
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo Pack", onExport_Combopack },
903
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
904
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo &Alias Pack", onExport_Comboaliaspack },
905
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
906
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Doorsets", onExport_Doorset },
907 };
908
909
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu export_menu
910 99 {
911 #ifdef _WIN32
912 { "&Package", onExport_Package },
913 #endif
914
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Enemies", onExport_Guys },
915
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Map", onExport_Map },
916
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&DMaps", onExport_DMaps },
917
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
918
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Strings (.tsv)", onExport_StringsTSV },
919
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "String Table (deprecated)", onExport_Msgs },
920
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
921
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Graphics", &export_graphics },
922
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
923
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2.50 (Broken)", &export_250_menu },
924 };
925
926
927
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu recent_menu
928 99 {
929
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
930
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
931
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
932
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
933
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
934
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
935
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
936
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
937
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
938
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
939 };
940 static char rec_menu_fullpaths[10][512];
941 static char rec_menu_strs[10][64];
942
943 int32_t customOpen(char const* path);
944 void do_recent_quest(uint32_t ind)
945 {
946 if(ind > 9) return;
947 strcpy(temppath, rec_menu_fullpaths[ind]);
948 customOpen(temppath);
949 }
950 int32_t do_RecentQuest_0() { do_recent_quest(0); return D_O_K; }
951 int32_t do_RecentQuest_1() { do_recent_quest(1); return D_O_K; }
952 int32_t do_RecentQuest_2() { do_recent_quest(2); return D_O_K; }
953 int32_t do_RecentQuest_3() { do_recent_quest(3); return D_O_K; }
954 int32_t do_RecentQuest_4() { do_recent_quest(4); return D_O_K; }
955 int32_t do_RecentQuest_5() { do_recent_quest(5); return D_O_K; }
956 int32_t do_RecentQuest_6() { do_recent_quest(6); return D_O_K; }
957 int32_t do_RecentQuest_7() { do_recent_quest(7); return D_O_K; }
958 int32_t do_RecentQuest_8() { do_recent_quest(8); return D_O_K; }
959 int32_t do_RecentQuest_9() { do_recent_quest(9); return D_O_K; }
960
961 2 void refresh_recent_menu()
962 {
963 2 int32_t (*procs[10])(void) = {
964 do_RecentQuest_0, do_RecentQuest_1, do_RecentQuest_2, do_RecentQuest_3,
965 do_RecentQuest_4, do_RecentQuest_5, do_RecentQuest_6,
966 do_RecentQuest_7, do_RecentQuest_8, do_RecentQuest_9
967 };
968
5/8
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✓ Branch 7 taken 1 times.
2 static MenuItem nilitem("---",nullptr,nullopt,true);
969
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 20 times.
22 for(auto q = 0; q < 10; ++q)
970 {
971 20 MenuItem& mit = *recent_menu.at(q);
972 20 bool valid = rec_menu_fullpaths[q][0] != '-';
973
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 20 times.
20 if(valid)
974 mit = MenuItem(rec_menu_strs[q],procs[q]);
975 20 else mit = nilitem;
976 20 }
977 2 }
978
979 1 void load_recent_quests()
980 {
981 1 char configname[64] = "rec_qst_";
982 1 char* ptr = &configname[strlen(configname)];
983 1 char buf[512] = {0};
984
2/2
✓ Branch 0 taken 10 times.
✓ Branch 1 taken 1 times.
11 for(auto q = 0; q < 10; ++q)
985 {
986 10 sprintf(ptr, "%d", q); //increment the configname value
987 10 char const* qst_str = zc_get_config("recent",configname,nullptr);
988
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 10 times.
10 if(qst_str[0])
989 {
990 strncpy(rec_menu_fullpaths[q], qst_str, 511);
991 relativize_path(buf, rec_menu_fullpaths[q]);
992 if(strlen(buf) > 62)
993 {
994 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
995 }
996 strncpy(rec_menu_strs[q], buf, 63);
997 }
998 else
999 {
1000 10 strcpy(rec_menu_fullpaths[q], "---");
1001 10 strcpy(rec_menu_strs[q], "---");
1002 }
1003 10 rec_menu_fullpaths[q][511] = 0;
1004 10 rec_menu_strs[q][63] = 0;
1005 10 }
1006 1 refresh_recent_menu();
1007 1 }
1008
1009 void write_recent_quests()
1010 {
1011 char configname[64] = "rec_qst_";
1012 char* ptr = &configname[strlen(configname)];
1013 for(auto q = 0; q < 10; ++q)
1014 {
1015 sprintf(ptr, "%d", q); //increment the configname value
1016 zc_set_config("recent",configname,(rec_menu_fullpaths[q][0]!='-') ? rec_menu_fullpaths[q] : nullptr);
1017 }
1018 }
1019
1020 void update_recent_quest(char const* path)
1021 {
1022 int32_t ind = -1;
1023 for(auto q = 0; q < 10; ++q)
1024 {
1025 if(!strcmp(path, rec_menu_fullpaths[q]))
1026 {
1027 ind = q;
1028 break;
1029 }
1030 }
1031 if(ind > -1)
1032 {
1033 for(auto q = ind; q > 0; --q)
1034 {
1035 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1036 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1037 }
1038 }
1039 else
1040 {
1041 int32_t free_ind = 9; //if none found, override the last index
1042 for(auto q = 0; q < 9; ++q)
1043 {
1044 if(rec_menu_fullpaths[q][0] == '-')
1045 {
1046 free_ind = q;
1047 break;
1048 }
1049 }
1050
1051 for(auto q = free_ind; q > 0; --q)
1052 {
1053 strcpy(rec_menu_fullpaths[q], rec_menu_fullpaths[q-1]);
1054 strcpy(rec_menu_strs[q], rec_menu_strs[q-1]);
1055 }
1056 }
1057 char buf[512] = {0};
1058 strcpy(rec_menu_fullpaths[0], path);
1059 relativize_path(buf, rec_menu_fullpaths[0]);
1060 if(strlen(buf) > 62)
1061 {
1062 buf[60] = buf[61] = buf[62] = '.'; //add "..." as the last 3 characters
1063 }
1064 strncpy(rec_menu_strs[0], buf, 63);
1065 refresh_recent_menu();
1066 zc_set_config("zquest",last_quest_name,path);
1067 write_recent_quests();
1068 }
1069
1070 void reload_zq_gui()
1071 {
1072 init_custom_fonts();
1073 load_size_poses();
1074 refresh_visible_screens();
1075 update_combobrush();
1076 refresh(rCLEAR|rALL);
1077 }
1078 void change_mapscr_zoom(int delta)
1079 {
1080 int num_screens = Map.getViewSize();
1081 num_screens = std::clamp(num_screens + delta, 1, mapscreen_num_screens_to_draw_max);
1082 Map.setViewSize(num_screens);
1083 std::string qst_cfg_header = qst_cfg_header_from_path(filepath);
1084 zc_set_config(qst_cfg_header.c_str(), "zoom_num_screens", Map.getViewSize());
1085 reload_zq_gui();
1086 }
1087 void toggle_is_compact()
1088 {
1089 is_compact = !is_compact;
1090 zc_set_config("ZQ_GUI","compact_mode",is_compact?1:0);
1091 reload_zq_gui();
1092 }
1093 void toggle_merged_mode()
1094 {
1095 if(is_compact)
1096 {
1097 compact_merged_combopane = !compact_merged_combopane;
1098 zc_set_config("ZQ_GUI","merge_cpane_compact",compact_merged_combopane?1:0);
1099 }
1100 else
1101 {
1102 large_merged_combopane = !large_merged_combopane;
1103 zc_set_config("ZQ_GUI","merge_cpane_large",large_merged_combopane?1:0);
1104 }
1105 reload_zq_gui();
1106 }
1107 void toggle_compact_sqr_mode()
1108 {
1109 compact_square_panels = !compact_square_panels;
1110 zc_set_config("ZQ_GUI","square_panels_compact",compact_square_panels?1:0);
1111 reload_zq_gui();
1112 }
1113 void cycle_compact_sqr(bool down)
1114 {
1115 if(!(is_compact && compact_square_panels))
1116 return;
1117 static const int num_panels = 3;
1118 if(down)
1119 compact_active_panel = (compact_active_panel+1)%num_panels;
1120 else
1121 compact_active_panel = (compact_active_panel-1+num_panels)%num_panels;
1122 reload_zq_gui();
1123 }
1124 void toggle_favzoom_mode()
1125 {
1126 if(is_compact)
1127 {
1128 compact_zoomed_fav = !compact_zoomed_fav;
1129 zc_set_config("ZQ_GUI","zoom_fav_compact",compact_zoomed_fav?1:0);
1130 }
1131 else
1132 {
1133 large_zoomed_fav = !large_zoomed_fav;
1134 zc_set_config("ZQ_GUI","zoom_fav_large",large_zoomed_fav?1:0);
1135 }
1136 reload_zq_gui();
1137 }
1138 void toggle_cmdzoom_mode()
1139 {
1140 if(is_compact)
1141 {
1142 compact_zoomed_cmd = !compact_zoomed_cmd;
1143 zc_set_config("ZQ_GUI","zoom_cmd_compact",compact_zoomed_cmd?1:0);
1144 }
1145 else
1146 {
1147 large_zoomed_cmd = !large_zoomed_cmd;
1148 zc_set_config("ZQ_GUI","zoom_cmd_large",large_zoomed_cmd?1:0);
1149 }
1150 reload_zq_gui();
1151 }
1152
1153 enum
1154 {
1155 MENUID_FILE_SAVE,
1156 MENUID_FILE_SAVEAS,
1157 MENUID_FILE_REVERT,
1158 };
1159
1160
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu file_menu
1161 126 {
1162
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&New", do_NewQuest },
1163
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Open", do_OpenQuest },
1164
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Load Tileset", onTileset },
1165
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Recent", &recent_menu },
1166
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1167
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Save", onSave, MENUID_FILE_SAVE },
1168
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Save &as...", onSaveAs, MENUID_FILE_SAVEAS },
1169
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Revert", onRevert, MENUID_FILE_REVERT },
1170
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1171
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Import", &import_menu },
1172
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Export", &export_menu },
1173 #ifndef __EMSCRIPTEN__
1174
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1175
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "E&xit", handle_quit },
1176 #endif
1177 };
1178
1179 enum
1180 {
1181 MENUID_MAPS_NEXT,
1182 MENUID_MAPS_PREV,
1183 };
1184
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu maps_menu
1185 54 {
1186
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Goto Map...", onGotoMap },
1187
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Next Map", onIncMap, MENUID_MAPS_NEXT },
1188
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Previous Map", onDecMap, MENUID_MAPS_PREV },
1189
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1190
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "D&elete Map", onDeleteMap },
1191 };
1192
1193
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu misc_menu
1194 90 {
1195
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "S&ubscreens", onEditSubscreens },
1196
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Shop Types", onShopTypes },
1197
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Bottle Types", onBottleTypes },
1198
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Bottle S&hop Types", onBottleShopTypes },
1199
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Info Types", onInfoTypes },
1200
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Warp Rings", onWarpRings },
1201
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Triforce Pieces", onTriPieces },
1202
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&End String", onEndString },
1203
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Item &Drop Sets", onItemDropSets },
1204 };
1205
1206
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu spr_menu
1207 36 {
1208
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Sprite Data", onCustomWpns },
1209
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Hero", onCustomHero },
1210
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Misc Sprites", onMiscSprites },
1211 };
1212
1213
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 NewMenu colors_menu
1214 36 {
1215
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Main ", onColors_Main },
1216
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Levels ", onColors_Levels },
1217
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Sprites ", onColors_Sprites },
1218 };
1219
1220
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu defs_menu
1221 81 {
1222
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Palettes", onDefault_Pals },
1223
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Tiles", onDefault_Tiles },
1224
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combos", onDefault_Combos },
1225
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Items", onDefault_Items },
1226
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Enemies", onDefault_Guys },
1227
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Sprite Data", onDefault_Weapons },
1228
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Map Styles", onDefault_MapStyles },
1229
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "SF&X Data", onDefault_SFX },
1230 };
1231
1232 int32_t onEditComboAlias();
1233 int32_t onEditComboPool();
1234 int32_t onEditAutoCombo();
1235
1236
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu graphics_menu
1237 90 {
1238
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Palettes ", &colors_menu },
1239
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Sprites ", &spr_menu },
1240
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combos", onCombos },
1241
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Tiles", onTiles },
1242
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Game icons", onIcons },
1243
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Misc co&lors", onMiscColors },
1244
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Map styles", onMapStyles },
1245
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Door Combo Sets", onDoorCombos },
1246
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo &Aliases", onEditComboAlias },
1247 };
1248
1249
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu audio_menu
1250 36 {
1251
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "SF&X Data", onSelectSFX },
1252
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&MIDIs", onMidis },
1253
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Mis&c SFX", onMiscSFX },
1254 };
1255
1256 void set_rules(byte* newrules);
1257
1258 void call_testqst_dialog();
1259 int32_t onTestQst()
1260 {
1261 call_testqst_dialog();
1262 return D_O_K;
1263 }
1264
1265 int32_t onRulesDlg()
1266 {
1267 call_qr_dialog(21, set_rules);
1268 return D_O_K;
1269 }
1270
1271 int32_t onRulesSearch()
1272 {
1273 call_qrsearch_dialog(set_rules);
1274 return D_O_K;
1275 }
1276
1277 int32_t onZScriptSettings()
1278 {
1279 ScriptRulesDialog(quest_rules, 17, [](byte* newrules)
1280 {
1281 saved = false;
1282 memcpy(quest_rules, newrules, QR_SZ);
1283 unpack_qrs();
1284 }).show();
1285 return D_O_K;
1286 }
1287
1288 void call_zinf_dlg();
1289 int32_t onZInfo()
1290 {
1291 call_zinf_dlg();
1292 return D_O_K;
1293 }
1294
1295
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu quest_menu
1296 144 {
1297
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Options ", onRulesDlg },
1298
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Test", onTestQst },
1299
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Items", onCustomItems },
1300
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Ene&mies", onCustomEnemies },
1301
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Hero", onCustomHero },
1302
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Strings", onStrings },
1303
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&DMaps", onDmaps },
1304
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "I&nit Data", onInit },
1305
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Misc D&ata ", &misc_menu },
1306
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&ZInfo", onZInfo },
1307
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1308
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Graphics ", &graphics_menu },
1309
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "A&udio ", &audio_menu },
1310
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1311
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "De&faults ", &defs_menu },
1312 };
1313
1314
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu paste_menu
1315 27 {
1316
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste &To All", onPasteToAll },
1317
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste &All To All", onPasteAllToAll },
1318 };
1319
1320
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu paste_item_menu
1321 117 {
1322
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Undercombo", onPasteUnderCombo },
1323
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Secret Combos", onPasteSecretCombos },
1324
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Freeform Combos", onPasteFFCombos },
1325
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Screen &Data", onPasteScreenData },
1326
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Warps", onPasteWarps },
1327
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Warp &Return", onPasteWarpLocations },
1328
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Enemies", onPasteEnemies },
1329
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Room &Type Data", onPasteRoom },
1330
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Guy/String", onPasteGuy },
1331
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Doo&rs", onPasteDoors },
1332
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Layers", onPasteLayers },
1333
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Palette", onPastePalette },
1334 };
1335
1336 enum
1337 {
1338 MENUID_EDIT_UNDO,
1339 MENUID_EDIT_REDO,
1340 MENUID_EDIT_COPY,
1341 MENUID_EDIT_PASTE,
1342 MENUID_EDIT_PASTEALL,
1343 MENUID_EDIT_ADVPASTE,
1344 MENUID_EDIT_SPECPASTE,
1345 MENUID_EDIT_DELETE,
1346 };
1347
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu edit_menu
1348 99 {
1349
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Undo", onUndo, MENUID_EDIT_UNDO },
1350
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Redo", onRedo, MENUID_EDIT_REDO },
1351
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Copy", onCopy, MENUID_EDIT_COPY },
1352
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Paste", onPaste, MENUID_EDIT_PASTE },
1353
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste A&ll", onPasteAll, MENUID_EDIT_PASTEALL },
1354
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Adv. Paste ", &paste_menu, MENUID_EDIT_ADVPASTE },
1355
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste &Spec. ", &paste_item_menu, MENUID_EDIT_SPECPASTE },
1356
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Delete", onDelete, MENUID_EDIT_DELETE },
1357
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1358
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Maps ", &maps_menu },
1359 };
1360
1361
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu drawing_mode_menu
1362 45 {
1363
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Normal", onDrawingModeNormal, dm_normal },
1364
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Alias", onDrawingModeAlias, dm_alias },
1365
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Pool", onDrawingModePool, dm_cpool },
1366
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Auto Combo", onDrawingModeAuto, dm_auto },
1367 };
1368
1369
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu integrity_check_menu
1370 36 {
1371
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&All ", onIntegrityCheckAll },
1372
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Screens ", onIntegrityCheckRooms },
1373
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Warps ", onIntegrityCheckWarps },
1374 };
1375
1376
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu quest_reports_menu
1377 81 {
1378
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Bugged Next-> Combo Locations", onBuggedNextComboLocationReport },
1379
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Locations", onComboLocationReport },
1380
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Combo Type Locations", onComboTypeLocationReport },
1381
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Enemy Locations", onEnemyLocationReport },
1382
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Item Locations", onItemLocationReport },
1383
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Script Locations", onScriptLocationReport },
1384
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&What Links Here", onWhatWarpsReport },
1385
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "In&tegrity Check ", &integrity_check_menu },
1386 };
1387
1388 int32_t onPalFix();
1389 int32_t onPitFix();
1390 1 int32_t onStrFix()
1391 {
1392
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(get_qr(qr_OLD_STRING_EDITOR_MARGINS))
1393 {
1394 AlertDialog("Fix: Old Margins",
1395 "Fixing margins may cause strings that used to spill outside the textbox"
1396 " to instead be cut off. Are you sure?",
1397 [&](bool ret,bool)
1398 {
1399 if(ret)
1400 {
1401 set_qr(qr_OLD_STRING_EDITOR_MARGINS, 0);
1402 saved = false;
1403 }
1404 }).show();
1405 }
1406
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if(get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT))
1407 {
1408 AlertDialog("Fix: Old Frame Size",
1409 "This will fix the frame size of all strings. No visual changes should occur,"
1410 " as the string width/height will be fixed, but the compat QR will also be unchecked.",
1411 [&](bool ret,bool)
1412 {
1413 if(ret)
1414 {
1415 for(auto q = 0; q < msg_count; ++q)
1416 {
1417 MsgStrings[q].w += 16;
1418 MsgStrings[q].h += 16;
1419 }
1420 set_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT, 0);
1421 saved = false;
1422 }
1423 }).show();
1424 }
1425 1 return D_O_K;
1426 }
1427
1428 int32_t onRemoveOldArrivalSquare();
1429 enum
1430 {
1431 MENUID_FIXTOOL_OLDSTRING,
1432 };
1433
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu fixtools_menu
1434 72 {
1435
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Color Set Fix", onCSetFix },
1436
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Liquid Solidity Fix", onWaterSolidity },
1437
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Effect Square Fix", onEffectFix },
1438
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Level Palette Fix", onPalFix },
1439
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Pit and Liquid Damage Fix", onPitFix },
1440
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Old Strings Fix", onStrFix, MENUID_FIXTOOL_OLDSTRING },
1441
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Green Arrival Square Fix", onRemoveOldArrivalSquare },
1442 };
1443
1444
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu tool_menu
1445 99 {
1446
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Combo &Flags", onFlags, nullopt, MFL_EXIT_PRE_PROC },
1447
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Fix &Tools ", &fixtools_menu },
1448
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&NES Dungeon Template", onTemplate },
1449
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Apply Template to All", onReTemplate },
1450
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1451
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Preview Mode", onPreviewMode },
1452
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Drawing &Mode ", &drawing_mode_menu },
1453
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1454
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&List Combos Used", onUsedCombos },
1455
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Quest Reports ", &quest_reports_menu },
1456 };
1457
1458 int32_t onLayer3BG()
1459 {
1460 ViewLayer3BG = ViewLayer3BG ? 0 : 1;
1461 zc_set_config("zquest","layer3_bg",ViewLayer3BG);
1462 return D_O_K;
1463 }
1464 int32_t onLayer2BG()
1465 {
1466 ViewLayer2BG = ViewLayer2BG ? 0 : 1;
1467 zc_set_config("zquest","layer2_bg",ViewLayer2BG);
1468 return D_O_K;
1469 }
1470 int onGridToggle();
1471 enum
1472 {
1473 MENUID_VIEW_WALKABILITY,
1474 MENUID_VIEW_FLAGS,
1475 MENUID_VIEW_CSET,
1476 MENUID_VIEW_TYPES,
1477 MENUID_VIEW_INFO,
1478 MENUID_VIEW_SQUARES,
1479 MENUID_VIEW_FFCS,
1480 MENUID_VIEW_SCRIPTNAMES,
1481 MENUID_VIEW_GRID,
1482 MENUID_VIEW_SCREENGRID,
1483 MENUID_VIEW_CURSCROUTLINE,
1484 MENUID_VIEW_DARKNESS,
1485 MENUID_VIEW_L2BG,
1486 MENUID_VIEW_L3BG,
1487 MENUID_VIEW_LAYERHIGHLIGHT,
1488 };
1489
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 NewMenu view_menu
1490 180 {
1491
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "View &Map...", onViewMap },
1492
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "View &Palette", onShowPal },
1493
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1494
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &Walkability", onShowWalkability, MENUID_VIEW_WALKABILITY },
1495
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &Flags", onShowFlags, MENUID_VIEW_FLAGS },
1496
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &CSets", onShowCSet, MENUID_VIEW_CSET },
1497
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &Types", onShowCType, MENUID_VIEW_TYPES },
1498
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1499
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show Screen &Info", onToggleShowInfo, MENUID_VIEW_INFO },
1500
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &Squares", onToggleShowSquares, MENUID_VIEW_SQUARES },
1501
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show FFCs", onToggleShowFFCs, MENUID_VIEW_FFCS },
1502
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show Script &Names", onToggleShowScripts, MENUID_VIEW_SCRIPTNAMES },
1503
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &Grid", onGridToggle, MENUID_VIEW_GRID },
1504
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show Screen G&rid", onToggleScreenGrid, MENUID_VIEW_SCREENGRID },
1505
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show Current Screen Outline", onToggleCurrentScreenOutline, MENUID_VIEW_CURSCROUTLINE },
1506
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Show &Darkness", onShowDarkness, MENUID_VIEW_DARKNESS },
1507
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Layer 2 is Background", onLayer2BG, MENUID_VIEW_L2BG },
1508
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Layer 3 is Background", onLayer3BG, MENUID_VIEW_L3BG },
1509
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Highlight Current Layer", onToggleHighlightLayer, MENUID_VIEW_LAYERHIGHLIGHT },
1510 };
1511
1512 9 void set_rules(byte* newrules)
1513 {
1514 9 saved = false;
1515
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(newrules != quest_rules)
1516 memcpy(quest_rules, newrules, QR_SZ);
1517 9 unpack_qrs();
1518
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
9 if(!get_qr(qr_ALLOW_EDITING_COMBO_0))
1519 {
1520 2 combobuf[0].walk = 0xF0;
1521 2 combobuf[0].type = 0;
1522 2 combobuf[0].flag = 0;
1523 2 }
1524
1525 // For 2.50.0 and 2.50.1
1526
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
9 if(get_qr(qr_VERYFASTSCROLLING))
1527 2 set_qr(qr_FASTDNGN, 1);
1528 9 }
1529
1530 int32_t onSelectFFCombo();
1531
1532 void onScreenNotes()
1533 {
1534 edit_screen_notes(Map.CurrScr(), Map.getCurrMap(), Map.getCurrScr());
1535 }
1536
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu data_menu
1537 162 {
1538
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Screen Data", onScrData },
1539
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Freeform Combos", onSelectFFCombo },
1540
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "La&yers", onLayers },
1541
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Tile Warp", onTileWarp },
1542
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Side &Warp", onSideWarp },
1543
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Secret &Combos", onSecretCombo },
1544
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Under Combo", onUnderCombo },
1545
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Doors", onDoors },
1546
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Maze Path", onPath },
1547
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1548
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Item", onItem },
1549
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Enemies", onEnemies },
1550
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Palette", onScreenPalette },
1551
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1552
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Room Data", onRoom },
1553
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Notes", onScreenNotes },
1554
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Browse Notes", browse_screen_notes },
1555 };
1556
1557
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu tunes_menu
1558 189 {
1559
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "ZC Forever", playZCForever },
1560
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Wind Fish", playTune1 },
1561
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Overworld", playTune2 },
1562
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Hyrule Castle", playTune3 },
1563
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Lost Woods", playTune4 },
1564
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Great Sea", playTune5 },
1565
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "East Hyrule", playTune6 },
1566
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Dancing Dragon", playTune7 },
1567
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Stone Tower", playTune8 },
1568
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Villages", playTune9 },
1569
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Swamp + Desert", playTune10 },
1570
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Outset Island", playTune11 },
1571
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Kakariko Village", playTune12 },
1572
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Clock Town", playTune13 },
1573
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Temple", playTune14 },
1574
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Dark World", playTune15 },
1575
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Dragon Roost", playTune16 },
1576
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Horse Race", playTune17 },
1577
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Credits", playTune18 },
1578
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Zelda's Lullaby", playTune19 },
1579 };
1580
1581 enum
1582 {
1583 MENUID_MEDIA_TUNES,
1584 MENUID_MEDIA_PLAYMUSIC,
1585 MENUID_MEDIA_CHANGETRACK,
1586 };
1587
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu media_menu
1588 45 {
1589
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Ambient Music ", &tunes_menu, MENUID_MEDIA_TUNES },
1590
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Play music", playMusic, MENUID_MEDIA_PLAYMUSIC },
1591
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Change track", changeTrack, MENUID_MEDIA_CHANGETRACK },
1592
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Stop tunes", stopMusic },
1593 };
1594
1595 enum
1596 {
1597 MENUID_ETC_VIDMODE,
1598 MENUID_ETC_FULLSCREEN,
1599 MENUID_ETC_DEBUG_CONSOLE,
1600 };
1601
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu etc_menu
1602 144 {
1603
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Help", &zq_help_menu },
1604
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&About", onAbout },
1605
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Video Mode", onZQVidMode, MENUID_ETC_VIDMODE },
1606
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Options...", onOptions },
1607
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Hotkeys...", do_zq_hotkey_dialog },
1608
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&List Hotkeys...", do_zq_list_hotkeys_dialog },
1609
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Fullscreen", onFullScreen, MENUID_ETC_FULLSCREEN },
1610
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1611
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&View Pic...", onViewPic },
1612
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Media", &media_menu },
1613
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1614
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Debug Console", toggleConsole, MENUID_ETC_DEBUG_CONSOLE },
1615
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Clear Quest Filepath", onClearQuestFilepath },
1616
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Take ZQ Snapshot", onSnapshot },
1617
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Take &Screen Snapshot", onMapscrSnapshot },
1618 };
1619
1620
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu zscript_menu
1621 63 {
1622
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Compile &ZScript...", onCompileScript },
1623
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1624
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Compiler Settings", onZScriptCompilerSettings },
1625
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Quest Script Settings", onZScriptSettings },
1626
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 {},
1627
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Import ZASM Script", onImportZASM },
1628 };
1629
1630 void set_console_state()
1631 {
1632 etc_menu.select_uid(MENUID_ETC_DEBUG_CONSOLE, console_is_open);
1633 }
1634
1635
3/16
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 9 times.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✗ Branch 9 not taken.
✗ Branch 10 not taken.
✗ Branch 11 not taken.
✗ Branch 12 not taken.
✗ Branch 13 not taken.
✗ Branch 14 not taken.
✗ Branch 15 not taken.
9 NewMenu foo_menu{{"FOO",[](){InfoDialog("PLACEHOLDER","THIS IS A PLACEHOLDER").show();}}};
1636
1637
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 TopMenu the_menu
1638 81 {
1639
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&File", &file_menu },
1640
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Quest", &quest_menu },
1641
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Edit", &edit_menu },
1642
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&View", &view_menu },
1643
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Tools", &tool_menu },
1644
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&Screen", &data_menu },
1645
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "&ZScript", &zscript_menu },
1646
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Et&C", &etc_menu },
1647 };
1648
1649 void rebuild_trans_table();
1650 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal,
1651 int32_t *px2, int32_t *py2, double *scale, bool isviewingmap, bool skipmenu = false);
1652
1653 int32_t onResetTransparency()
1654 {
1655 restore_mouse();
1656 rebuild_trans_table();
1657 jwin_alert("Notice","Translucency Table Rebuilt",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
1658
1659 refresh(rALL);
1660 return D_O_K;
1661 }
1662
1663 int32_t onFullScreen()
1664 {
1665 get_palette(RAMpal);
1666 bool windowed=is_windowed_mode()!=0;
1667 all_toggle_fullscreen(windowed);
1668
1669 gui_mouse_focus=0;
1670 gui_bg_color=jwin_pal[jcBOX];
1671 gui_fg_color=jwin_pal[jcBOXFG];
1672 MouseSprite::set(ZQM_NORMAL);
1673 zc_set_palette(RAMpal);
1674 position_mouse(zq_screen_w/2,zq_screen_h/2);
1675 set_display_switch_mode(SWITCH_BACKGROUND);
1676 set_display_switch_callback(SWITCH_OUT, switch_out);
1677 set_display_switch_callback(SWITCH_IN, switch_in);
1678 zc_set_config("zquest","fullscreen", is_windowed_mode() ? 0 : 1);
1679 return D_REDRAW;
1680 }
1681
1682 int32_t onEnter()
1683 {
1684 if(key[KEY_ALT]||key[KEY_ALTGR])
1685 {
1686 return onFullScreen();
1687 }
1688
1689 return D_O_K;
1690 }
1691
1692 //PROC, x, y, w, h, fg, bg, key, flags, d1, d2, *dp, *dp2, *dp3
1693
1694 //*text, (*proc), *child, flags, *dp
1695
1696 void run_zq_frame();
1697 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c);
1698
1699
1700 /*int32_t onY()
1701 {
1702 return D_O_K;
1703 }*/
1704
1705 int32_t onToggleGrid(bool color)
1706 {
1707 if(color)
1708 {
1709 GridColor=(GridColor+8)%16;
1710 zc_set_config("zquest", "grid_color", GridColor);
1711 }
1712 else
1713 {
1714 ShowGrid=!ShowGrid;
1715 zc_set_config("zquest","show_grid",ShowGrid);
1716 }
1717
1718 return D_O_K;
1719 }
1720
1721 int onGridToggle()
1722 {
1723 return onToggleGrid(CHECK_CTRL_CMD);
1724 }
1725
1726 int32_t onToggleScreenGrid()
1727 {
1728 ShowScreenGrid=!ShowScreenGrid;
1729 zc_set_config("zquest","show_screen_grid",ShowScreenGrid);
1730 return D_O_K;
1731 }
1732
1733 int32_t onToggleCurrentScreenOutline()
1734 {
1735 ShowCurScreenOutline=!ShowCurScreenOutline;
1736 zc_set_config("zquest","show_current_screen_outline",ShowCurScreenOutline);
1737 return D_O_K;
1738 }
1739
1740 int32_t onToggleShowScripts()
1741 {
1742 ShowFFScripts=!ShowFFScripts;
1743 zc_set_config("zquest","showffscripts",ShowFFScripts);
1744 return D_O_K;
1745 }
1746
1747 int32_t onToggleShowFFCs()
1748 {
1749 ShowFFCs=!ShowFFCs;
1750 zc_set_config("zquest","showffcs",ShowFFCs);
1751 return D_O_K;
1752 }
1753
1754 int32_t onToggleShowSquares()
1755 {
1756 ShowSquares=!ShowSquares;
1757 zc_set_config("zquest","showsquares",ShowSquares);
1758 return D_O_K;
1759 }
1760
1761 int32_t onToggleShowInfo()
1762 {
1763 ShowInfo=!ShowInfo;
1764 zc_set_config("zquest","showinfo",ShowInfo);
1765 return D_O_K;
1766 }
1767
1768 int32_t onToggleHighlightLayer()
1769 {
1770 ActiveLayerHighlight = ActiveLayerHighlight ? 0 : 1;
1771 zc_set_config("zquest","hl_active_lyr",ActiveLayerHighlight);
1772 return D_O_K;
1773 }
1774
1775 int onKeySlash()
1776 {
1777 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1778 {
1779 onAbout();
1780 }
1781 return D_O_K;
1782 }
1783
1784 int onAKey()
1785 {
1786 if(prv_mode)
1787 Map.set_prvadvance(1);
1788 return D_O_K;
1789 }
1790
1791 int onReloadPreview()
1792 {
1793 if(prv_mode)
1794 {
1795 Map.set_prvscr(Map.get_prv_map(), Map.get_prv_scr());
1796 Map.set_prvcmb(0);
1797 }
1798 return D_O_K;
1799 }
1800 int onSecretsPreview()
1801 {
1802 if(prv_mode)
1803 {
1804 Map.prv_secrets(false);
1805 refresh(rALL);
1806 }
1807 return D_O_K;
1808 }
1809
1810 int onSKey()
1811 {
1812 if(CHECK_CTRL_CMD)
1813 {
1814 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
1815 {
1816 onSaveAs();
1817 }
1818 else
1819 {
1820 if(!saved)
1821 onSave();
1822 }
1823 }
1824 else if(prv_mode)
1825 {
1826 Map.prv_secrets(false);
1827 refresh(rALL);
1828 }
1829 else onStrings();
1830 return D_O_K;
1831 }
1832 int onSetNewLayer(int newlayer)
1833 {
1834 CurrentLayer = newlayer;
1835 refresh(rALL);
1836 return D_O_K;
1837 }
1838 void lpal_dsa()
1839 {
1840 info_dsa("Level Palette Shortcuts",
1841 "You currently have level palette shortcuts disabled."
1842 " These can be re-enabled in 'Etc->Options', on the toggle 'Disable Level Palette Shortcuts'.",
1843 "dsa_lpal");
1844 }
1845 int onScreenLPal(int lpal)
1846 {
1847 if(DisableLPalShortcuts)
1848 {
1849 lpal_dsa();
1850 return D_O_K;
1851 }
1852 saved=false;
1853 Map.setcolor(lpal);
1854 refresh(rSCRMAP);
1855 return D_O_K;
1856 }
1857
1858 int32_t onPressEsc()
1859 {
1860 if(zoomed_minimap)
1861 mmap_set_zoom(false);
1862 else return onExit();
1863 return D_O_K;
1864 }
1865
1866 static DIALOG dialogs[] =
1867 {
1868 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
1869 { d_nbmenu_proc, 0, 0, 0, 13, 0, 0, 0, D_USER, 0, 0, (void *) &the_menu, NULL, NULL },
1870 { d_zq_hotkey_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1871
1872 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
1873 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_ESC, 0, (void *) onPressEsc, NULL, NULL },
1874 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 39, 0, 0, 0, (void *) onUsedCombos, NULL, NULL },
1875 { d_vsync_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1876 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1877 };
1878
1879
1880 int32_t onDecColour()
1881 {
1882 if ( CHECK_CTRL_CMD )
1883 {
1884 return onDecScrPal16();
1885 }
1886
1887 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1888 {
1889 return onDecScrPal();
1890 }
1891
1892 else
1893 {
1894 return onDecreaseCSet();
1895 }
1896 }
1897
1898 int32_t onIncColour()
1899 {
1900
1901 if ( CHECK_CTRL_CMD )
1902 {
1903 return onIncScrPal16();
1904 }
1905
1906 else if ( key[KEY_LSHIFT] || key[KEY_RSHIFT] )
1907 {
1908 return onIncScrPal();
1909 }
1910
1911 else
1912 {
1913 return onIncreaseCSet();
1914 }
1915 }
1916
1917 static DIALOG getnum_dlg[] =
1918 {
1919 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1920 9 { jwin_win_proc, 80, 80, 160, 72, vc(0), vc(11), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
1921 9 { jwin_rtext_proc, 114, 104+4, 48, 8, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) "Value:", NULL, NULL },
1922 9 { jwin_edit_proc, 168, 104, 48, 16, 0, 0, 0, 0, 6, 0, NULL, NULL, NULL },
1923 9 { jwin_button_proc, 90, 126, 61, 21, vc(0), vc(11), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
1924 9 { jwin_button_proc, 170, 126, 61, 21, vc(0), vc(11), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1925 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1926 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1927 };
1928
1929 int32_t getnumber(const char *prompt,int32_t initialval)
1930 {
1931 cancelgetnum=true;
1932 char buf[20];
1933 sprintf(buf,"%d",initialval);
1934 getnum_dlg[0].dp=(void *)prompt;
1935 getnum_dlg[0].dp2=get_zc_font(font_lfont);
1936 getnum_dlg[2].dp=(void *)buf;
1937
1938 large_dialog(getnum_dlg);
1939
1940 int32_t ret=do_zqdialog(getnum_dlg,2);
1941
1942 if(ret!=0&&ret!=4)
1943 {
1944 cancelgetnum=false;
1945 }
1946
1947 if(ret==3)
1948 return atoi(buf);
1949
1950 return initialval;
1951 }
1952
1953 static DIALOG save_tiles_dlg[] =
1954 {
1955 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
1956
1957
1958 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Tile Pack", NULL, NULL },
1959 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
1960 //for future tabs
1961 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1962 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
1963 //4
1964 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
1965 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1966 //6
1967 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
1968 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
1969 //8
1970 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
1971 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
1972 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
1973 };
1974
1975
1976 void savesometiles(const char *prompt,int32_t initialval)
1977 {
1978
1979 char firsttile[8], tilecount[8];
1980 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
1981 sprintf(firsttile,"%d",0);
1982 sprintf(tilecount,"%d",1);
1983 //int32_t ret;
1984
1985
1986
1987 save_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
1988
1989 sprintf(firsttile,"%d",0);
1990 sprintf(tilecount,"%d",1);
1991
1992 save_tiles_dlg[5].dp = firsttile;
1993 save_tiles_dlg[7].dp = tilecount;
1994
1995 large_dialog(save_tiles_dlg);
1996
1997 int32_t ret = do_zqdialog(save_tiles_dlg,-1);
1998 jwin_center_dialog(save_tiles_dlg);
1999
2000 if(ret == 8)
2001 {
2002 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2003 the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2004 if(prompt_for_new_file_compat("Save ZTILE(.ztile)", "ztile", NULL,datapath,false))
2005 {
2006 char name[PATH_MAX];
2007 extract_name(temppath,name,FILENAMEALL);
2008 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2009 if(f)
2010 {
2011 writetilefile(f,first_tile_id,the_tile_count);
2012 pack_fclose(f);
2013 char tmpbuf[PATH_MAX+20]={0};
2014 sprintf(tmpbuf,"Saved %s",name);
2015 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2016 }
2017 }
2018 }
2019 }
2020
2021 static DIALOG read_tiles_dlg[] =
2022 {
2023 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2024
2025
2026 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Tilepack To:", NULL, NULL },
2027 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2028 //for future tabs
2029 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2030 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2031 //4
2032 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2033 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2034 //6
2035 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2036 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2037 //8
2038 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2039 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2040 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2041 };
2042
2043
2044 void writesometiles_to(const char *prompt,int32_t initialval)
2045 {
2046
2047 char firsttile[8];;
2048 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2049 sprintf(firsttile,"%d",0);
2050 //int32_t ret;
2051
2052
2053
2054 read_tiles_dlg[0].dp2 = get_zc_font(font_lfont);
2055
2056 sprintf(firsttile,"%d",0);
2057 //sprintf(tilecount,"%d",1);
2058
2059 read_tiles_dlg[5].dp = firsttile;
2060
2061 large_dialog(read_tiles_dlg);
2062
2063 int32_t ret = do_zqdialog(read_tiles_dlg,-1);
2064 jwin_center_dialog(read_tiles_dlg);
2065
2066 if(ret == 8)
2067 {
2068 first_tile_id = vbound(atoi(firsttile), 0, NEWMAXTILES);
2069 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2070 if(prompt_for_existing_file_compat("Load ZTILE(.ztile)", "ztile", NULL,datapath,false))
2071 {
2072
2073 char name[256];
2074 extract_name(temppath,name,FILENAMEALL);
2075 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2076 if(f)
2077 {
2078
2079 if (!readtilefile_to_location(f,first_tile_id))
2080 {
2081 al_trace("Could not read from .ztile packfile %s\n", name);
2082 jwin_alert("ZTILE File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2083 }
2084 else
2085 {
2086 jwin_alert("ZTILE File: Success!","Loaded the source tiles to your tile sheets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2087 }
2088 pack_fclose(f);
2089 }
2090 }
2091 }
2092 }
2093
2094
2095 static DIALOG save_combofiles_dlg[] =
2096 {
2097 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2098
2099
2100 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Pack", NULL, NULL },
2101 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2102 //for future tabs
2103 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2104 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2105 //4
2106 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2107 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2108 //6
2109 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2110 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2111 //8
2112 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2113 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2114 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2115 };
2116
2117
2118 void savesomecombos(const char *prompt,int32_t initialval)
2119 {
2120
2121 char firsttile[8], tilecount[8];
2122 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2123 sprintf(firsttile,"%d",0);
2124 sprintf(tilecount,"%d",1);
2125 //int32_t ret;
2126
2127
2128
2129 save_combofiles_dlg[0].dp2 = get_zc_font(font_lfont);
2130
2131 sprintf(firsttile,"%d",0);
2132 sprintf(tilecount,"%d",1);
2133
2134 save_combofiles_dlg[5].dp = firsttile;
2135 save_combofiles_dlg[7].dp = tilecount;
2136
2137 large_dialog(save_combofiles_dlg);
2138
2139 int32_t ret = do_zqdialog(save_combofiles_dlg,-1);
2140 jwin_center_dialog(save_combofiles_dlg);
2141
2142 if(ret == 8)
2143 {
2144 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2145 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOS-1)-first_tile_id);
2146 if(prompt_for_new_file_compat("Save ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2147 {
2148 char name[PATH_MAX];
2149 extract_name(temppath,name,FILENAMEALL);
2150 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2151 if(f)
2152 {
2153 writecombofile(f,first_tile_id,the_tile_count);
2154 pack_fclose(f);
2155 char tmpbuf[PATH_MAX+20]={0};
2156 sprintf(tmpbuf,"Saved %s",name);
2157 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2158 }
2159 }
2160 }
2161 }
2162
2163
2164 static DIALOG load_comboset_dlg[] =
2165 {
2166 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2167
2168
2169 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Set (Range)", NULL, NULL },
2170 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2171 //for future tabs
2172 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2173 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2174 //4
2175 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2176 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2177 //6
2178 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2179 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2180 //8
2181 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2182 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2183 { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2184
2185 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2186 };
2187
2188 void writesomecombos(const char *prompt,int32_t initialval)
2189 {
2190
2191 char firsttile[8];
2192 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2193 sprintf(firsttile,"%d",0);
2194 //int32_t ret;
2195
2196
2197
2198 load_comboset_dlg[0].dp2 = get_zc_font(font_lfont);
2199
2200 sprintf(firsttile,"%d",0);
2201 //sprintf(tilecount,"%d",1);
2202
2203 load_comboset_dlg[5].dp = firsttile;
2204
2205 byte nooverwrite = 0;
2206
2207
2208 large_dialog(load_comboset_dlg);
2209
2210 int32_t ret = do_zqdialog(load_comboset_dlg,-1);
2211 jwin_center_dialog(load_comboset_dlg);
2212
2213 if(ret == 8)
2214 {
2215 if (load_comboset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2216
2217 al_trace("Nooverwrite is: %d\n", nooverwrite);
2218 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2219 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2220 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2221 {
2222 char name[256];
2223 extract_name(temppath,name,FILENAMEALL);
2224 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2225 if(f)
2226 {
2227
2228 if (!readcombofile(f,first_tile_id,nooverwrite))
2229 {
2230 al_trace("Could not read from .zcombo packfile %s\n", name);
2231 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2232 }
2233 else
2234 {
2235 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2236 saved=false;
2237 }
2238 pack_fclose(f);
2239 }
2240
2241 }
2242 }
2243 }
2244
2245 static DIALOG load_combopack_dlg[] =
2246 {
2247 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2248
2249
2250 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import Full Combo Package 1:1", NULL, NULL },
2251 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2252 //for future tabs
2253 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2254 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2255 //4
2256 { d_dummy_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2257 { d_dummy_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2258 //6
2259 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2260 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2261 //8
2262 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2263 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2264 { jwin_check_proc, 10, 42, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2265
2266 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2267 };
2268
2269 void loadcombopack(const char *prompt,int32_t initialval)
2270 {
2271
2272 char firsttile[8];
2273 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2274 sprintf(firsttile,"%d",0);
2275 //int32_t ret;
2276
2277
2278
2279 load_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2280
2281 sprintf(firsttile,"%d",0);
2282 //sprintf(tilecount,"%d",1);
2283
2284 load_combopack_dlg[5].dp = firsttile;
2285
2286 byte nooverwrite = 0;
2287
2288
2289 large_dialog(load_combopack_dlg);
2290
2291 int32_t ret = do_zqdialog(load_combopack_dlg,-1);
2292 jwin_center_dialog(load_combopack_dlg);
2293
2294 if(ret == 8)
2295 {
2296 if (load_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2297
2298 al_trace("Nooverwrite is: %d\n", nooverwrite);
2299 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2300 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2301 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2302 {
2303 char name[256];
2304 extract_name(temppath,name,FILENAMEALL);
2305 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2306 if(f)
2307 {
2308 //need dialogue here
2309 if (!readcombofile(f,0,nooverwrite))
2310 {
2311 al_trace("Could not read from .zcombo packfile %s\n", name);
2312 jwin_alert("ZCOMBO File: Error","Could not load the specified Tile.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2313 }
2314 else
2315 {
2316 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2317 saved=false;
2318 }
2319 }
2320
2321 pack_fclose(f);
2322 }
2323 }
2324 }
2325
2326
2327 static DIALOG read_combopack_dlg[] =
2328 {
2329 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2330
2331
2332 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combos (Specific Dest)", NULL, NULL },
2333 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2334 //for future tabs
2335 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2336 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2337 //4
2338 { jwin_text_proc, 10, 24, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2339 { jwin_edit_proc, 55, 22, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2340 //6
2341 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2342 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2343 //8
2344 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2345 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2346 //10
2347 { jwin_check_proc, 10, 58, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2348 //11
2349 { jwin_text_proc, 10, 42, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Skip:", NULL, NULL },
2350 //12
2351 { jwin_edit_proc, 55, 40, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2352
2353 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2354 };
2355
2356
2357
2358 void writesomecombos_to(const char *prompt,int32_t initialval)
2359 {
2360
2361 char firsttile[8];
2362 char skiptile[8];
2363 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2364 sprintf(firsttile,"%d",0);
2365 //int32_t ret;
2366
2367
2368
2369 read_combopack_dlg[0].dp2 = get_zc_font(font_lfont);
2370
2371 sprintf(skiptile,"%d",0);
2372 //sprintf(tilecount,"%d",1);
2373
2374 read_combopack_dlg[5].dp = firsttile;
2375
2376 byte nooverwrite = 0;
2377 int32_t skipover = 0;
2378
2379 sprintf(skiptile,"%d",0);
2380 //sprintf(tilecount,"%d",1);
2381
2382 read_combopack_dlg[12].dp = skiptile;
2383
2384 large_dialog(read_combopack_dlg);
2385
2386 int32_t ret = do_zqdialog(read_combopack_dlg,-1);
2387 jwin_center_dialog(read_combopack_dlg);
2388
2389 if(ret == 8)
2390 {
2391 if (read_combopack_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2392
2393 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOS-1));
2394 skipover = vbound(atoi(skiptile), 0, (MAXCOMBOS-1));
2395 al_trace("skipover is: %d\n", skipover);
2396 //skipover = vbound(skipover, 0, (MAXCOMBOS-1-skipover));
2397 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2398 if(prompt_for_existing_file_compat("Load ZCOMBO(.zcombo)", "zcombo", NULL,datapath,false))
2399 {
2400 char name[256];
2401 extract_name(temppath,name,FILENAMEALL);
2402 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2403 if(f)
2404 {
2405
2406 if (!readcombofile_to_location(f,first_tile_id,nooverwrite, skipover))
2407 {
2408 al_trace("Could not read from .zcombo packfile %s\n", name);
2409 jwin_alert("ZCOMBO File: Error","Could not load the specified combos.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2410 }
2411 else
2412 {
2413 jwin_alert("ZCOMBO File: Success!","Loaded the source combos to your combo pages!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2414 saved=false;
2415 }
2416 pack_fclose(f);
2417 }
2418
2419 }
2420 }
2421 }
2422
2423
2424
2425 static DIALOG save_dmaps_dlg[] =
2426 {
2427 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2428
2429
2430 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save DMaps (.zdmap)", NULL, NULL },
2431 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2432 //for future tabs
2433 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2434 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2435 //4
2436 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2437 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2438 //6
2439 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Last", NULL, NULL },
2440 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2441 //8
2442 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2443 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2444 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2445 };
2446
2447
2448 void savesomedmaps(const char *prompt,int32_t initialval)
2449 {
2450
2451 char firstdmap[8], lastdmap[8];
2452 int32_t first_dmap_id = 0; int32_t last_dmap_id = 0;
2453 sprintf(firstdmap,"%d",0);
2454 sprintf(lastdmap,"%d",1);
2455 //int32_t ret;
2456
2457
2458
2459 save_dmaps_dlg[0].dp2 = get_zc_font(font_lfont);
2460
2461 sprintf(firstdmap,"%d",0);
2462 sprintf(lastdmap,"%d",0);
2463
2464 save_dmaps_dlg[5].dp = firstdmap;
2465 save_dmaps_dlg[7].dp = lastdmap;
2466
2467 large_dialog(save_dmaps_dlg);
2468
2469 int32_t ret = do_zqdialog(save_dmaps_dlg,-1);
2470 jwin_center_dialog(save_dmaps_dlg);
2471
2472 if(ret == 8)
2473 {
2474 first_dmap_id = vbound(atoi(firstdmap), 0, MAXDMAPS-1);
2475 last_dmap_id = vbound(atoi(lastdmap), 0, MAXDMAPS-1);
2476
2477 if ( last_dmap_id < first_dmap_id )
2478 {
2479 int32_t swap = last_dmap_id;
2480 last_dmap_id = first_dmap_id;
2481 first_dmap_id = swap;
2482 }
2483 if(!prompt_for_new_file_compat("Export DMaps (.zdmap)","zdmap",NULL,datapath,false))
2484
2485
2486 saved=false;
2487
2488 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2489 if(f)
2490 {
2491 if(!writesomedmaps(f,first_dmap_id,last_dmap_id,MAXDMAPS))
2492 {
2493 char buf[PATH_MAX+20],name[PATH_MAX];
2494 extract_name(temppath,name,FILENAMEALL);
2495 sprintf(buf,"Unable to load %s",name);
2496 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2497 }
2498 else
2499 {
2500 char name[PATH_MAX];
2501 extract_name(temppath,name,FILENAMEALL);
2502 char tmpbuf[PATH_MAX+20]={0};
2503 sprintf(tmpbuf,"Saved %s",name);
2504 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2505 }
2506 }
2507 pack_fclose(f);
2508 }
2509 }
2510
2511 static DIALOG save_comboaliasfiles_dlg[] =
2512 {
2513 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2514
2515
2516 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Combo Alias Pack", NULL, NULL },
2517 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2518 //for future tabs
2519 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2520 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2521 //4
2522 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2523 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2524 //6
2525 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2526 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2527 //8
2528 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2529 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2530 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2531 };
2532
2533
2534 void savesomecomboaliases(const char *prompt,int32_t initialval)
2535 {
2536
2537 char firsttile[8], tilecount[8];
2538 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2539 sprintf(firsttile,"%d",0);
2540 sprintf(tilecount,"%d",1);
2541 //int32_t ret;
2542
2543
2544
2545 save_comboaliasfiles_dlg[0].dp2 = get_zc_font(font_lfont);
2546
2547 sprintf(firsttile,"%d",0);
2548 sprintf(tilecount,"%d",1);
2549
2550 save_comboaliasfiles_dlg[5].dp = firsttile;
2551 save_comboaliasfiles_dlg[7].dp = tilecount;
2552
2553 large_dialog(save_comboaliasfiles_dlg);
2554
2555 int32_t ret = do_zqdialog(save_comboaliasfiles_dlg,-1);
2556 jwin_center_dialog(save_comboaliasfiles_dlg);
2557
2558 if(ret == 8)
2559 {
2560 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2561 the_tile_count = vbound(atoi(tilecount), 1, (MAXCOMBOALIASES-1)-first_tile_id);
2562 if(prompt_for_new_file_compat("Save ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2563 {
2564 char name[PATH_MAX];
2565 extract_name(temppath,name,FILENAMEALL);
2566 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2567 if(f)
2568 {
2569 writecomboaliasfile(f,first_tile_id,the_tile_count);
2570 pack_fclose(f);
2571 char tmpbuf[PATH_MAX+20]={0};
2572 sprintf(tmpbuf,"Saved %s",name);
2573 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2574 }
2575 }
2576 }
2577 }
2578
2579
2580 static DIALOG read_comboaliaspack_dlg[] =
2581 {
2582 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2583
2584
2585 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Load Combo Pack To:", NULL, NULL },
2586 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2587 //for future tabs
2588 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2589 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2590 //4
2591 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Starting at:", NULL, NULL },
2592 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2593 //6
2594 { d_dummy_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2595 { d_dummy_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2596 //8
2597 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2598 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2599 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2600 };
2601
2602
2603 void writesomecomboaliases_to(const char *prompt,int32_t initialval)
2604 {
2605
2606 char firsttile[8];;
2607 int32_t first_tile_id = 0; int32_t the_tile_count = 1;
2608 sprintf(firsttile,"%d",0);
2609 //int32_t ret;
2610
2611
2612
2613 read_comboaliaspack_dlg[0].dp2 = get_zc_font(font_lfont);
2614
2615 sprintf(firsttile,"%d",0);
2616 //sprintf(tilecount,"%d",1);
2617
2618 read_comboaliaspack_dlg[5].dp = firsttile;
2619
2620 large_dialog(read_comboaliaspack_dlg);
2621
2622 int32_t ret = do_zqdialog(read_comboaliaspack_dlg,-1);
2623 jwin_center_dialog(read_comboaliaspack_dlg);
2624
2625 if(ret == 8)
2626 {
2627 first_tile_id = vbound(atoi(firsttile), 0, (MAXCOMBOALIASES-1));
2628 //the_tile_count = vbound(atoi(tilecount), 1, NEWMAXTILES-first_tile_id);
2629 if(prompt_for_existing_file_compat("Load ZALIAS(.zalias)", "zalias", NULL,datapath,false))
2630 {
2631 char name[256];
2632 extract_name(temppath,name,FILENAMEALL);
2633 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2634 if(f)
2635 {
2636
2637 if (!readcomboaliasfile_to_location(f,first_tile_id))
2638 {
2639 al_trace("Could not read from .zcombo packfile %s\n", name);
2640 jwin_alert("ZALIAS File: Error","Could not load the specified combo aliases.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2641 }
2642 else
2643 {
2644 jwin_alert("ZALIAS File: Success!","Loaded the source combos to your combo alias table!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2645 saved=false;
2646 }
2647 pack_fclose(f);
2648 }
2649 }
2650 }
2651 }
2652
2653
2654
2655
2656 //Doorsets
2657
2658 static DIALOG save_doorset_dlg[] =
2659 {
2660 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2661 { jwin_win_proc, 0, 0, 120, 100, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Save Doorset", NULL, NULL },
2662 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2663 //for future tabs
2664 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2665 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2666 //4
2667 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First", NULL, NULL },
2668 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2669 //6
2670 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2671 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2672 //8
2673 { jwin_button_proc, 15, 72, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Save", NULL, NULL },
2674 { jwin_button_proc, 69, 72, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2675 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2676 };
2677
2678
2679 void do_exportdoorset(const char *prompt,int32_t initialval)
2680 {
2681 char firstdoor[8], doorct[8];
2682 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2683 sprintf(firstdoor,"%d",0);
2684 sprintf(doorct,"%d",1);
2685 //int32_t ret;
2686 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2687
2688 sprintf(firstdoor,"%d",0);
2689 sprintf(doorct,"%d",1);
2690
2691 save_doorset_dlg[5].dp = firstdoor;
2692 save_doorset_dlg[7].dp = doorct;
2693
2694 large_dialog(save_doorset_dlg);
2695
2696 int32_t ret = do_zqdialog(save_doorset_dlg,-1);
2697 jwin_center_dialog(save_doorset_dlg);
2698
2699 if(ret == 8) //OK
2700 {
2701 /* sanity bounds
2702 first_doorset_id = vbound(atoi(firstdoor), 0, (MAXCOMBOS-1));
2703 the_doorset_count = vbound(atoi(doorct), 1, (MAXCOMBOS-1)-first_doorset_id);
2704 */
2705 if(prompt_for_new_file_compat("Save ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2706 {
2707 char name[256];
2708 extract_name(temppath,name,FILENAMEALL);
2709 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
2710 if(f)
2711 {
2712 writezdoorsets(f,first_doorset_id,the_doorset_count);
2713 pack_fclose(f);
2714 char tmpbuf[512]={0};
2715 sprintf(tmpbuf,"Saved %s",name);
2716 jwin_alert("Success!",tmpbuf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2717 }
2718 }
2719 }
2720 }
2721
2722 static DIALOG load_doorset_dlg[] =
2723 {
2724 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
2725 { jwin_win_proc, 0, 0, 120, 124, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Door Set (Range)", NULL, NULL },
2726 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
2727 //for future tabs
2728 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2729 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
2730 //4
2731 { jwin_text_proc, 10, 28, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "First:", NULL, NULL },
2732 { jwin_edit_proc, 55, 26, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2733 //6
2734 { jwin_text_proc, 10, 46, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Count", NULL, NULL },
2735 { jwin_edit_proc, 55, 44, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2736 //8
2737 { jwin_button_proc, 15, 92, 36, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Load", NULL, NULL },
2738 { jwin_button_proc, 69, 92, 36, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
2739 //10
2740 { jwin_text_proc, 10, 64, 20, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Dest", NULL, NULL },
2741 { jwin_edit_proc, 55, 63, 40, 16, vc(12), vc(1), 0, 0, 63, 0, NULL, NULL, NULL },
2742 //8
2743
2744 // { jwin_check_proc, 10, 46, 95, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Don't Overwrite", NULL, NULL },
2745
2746 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
2747 };
2748
2749 void do_importdoorset(const char *prompt,int32_t initialval)
2750 {
2751
2752 char firstdoor[8], doorct[8], destid[8];
2753 int32_t first_doorset_id = 0; int32_t the_doorset_count = 1;
2754 int32_t the_dest_id = 0;
2755 sprintf(firstdoor,"%d",0);
2756 sprintf(doorct,"%d",1);
2757 sprintf(destid,"%d",0);
2758 //int32_t ret;
2759
2760 save_doorset_dlg[0].dp2 = get_zc_font(font_lfont);
2761
2762 load_doorset_dlg[5].dp = firstdoor;
2763 load_doorset_dlg[7].dp = doorct;
2764 load_doorset_dlg[11].dp = destid;
2765
2766 byte nooverwrite = 0;
2767
2768 large_dialog(load_doorset_dlg);
2769
2770 int32_t ret = do_zqdialog(load_doorset_dlg,-1);
2771 jwin_center_dialog(load_doorset_dlg);
2772
2773 if(ret == 8) //OK
2774 {
2775 //if (load_doorset_dlg[10].flags & D_SELECTED) nooverwrite = 1;
2776
2777 //sanity bound
2778 first_doorset_id = vbound(atoi(firstdoor), 0, door_combo_set_count);
2779 the_doorset_count = vbound(atoi(doorct), 1, door_combo_set_count);
2780 the_dest_id = vbound(atoi(destid), 0, door_combo_set_count);
2781 if(prompt_for_existing_file_compat("Load ZDOORS(.zdoors)", "zdoors", NULL,datapath,false))
2782 {
2783 char name[256];
2784 extract_name(temppath,name,FILENAMEALL);
2785 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
2786 if(f)
2787 {
2788 int32_t ret = readzdoorsets(f,first_doorset_id,the_doorset_count, the_dest_id);
2789
2790 if (!ret)
2791 {
2792 al_trace("Could not read from .zdoors packfile %s\n", name);
2793 jwin_alert("ZDOORS File: Error","Could not load the specified doorsets.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2794 }
2795 else if ( ret == 1 )
2796 {
2797 jwin_alert("ZDOORS File: Success!","Loaded the source doorsets!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2798 saved=false;
2799 }
2800 else if ( ret == 2 )
2801 {
2802 jwin_alert("ZDOORS File: Issue:","Targets exceed doorset count!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
2803 saved=false;
2804 }
2805 pack_fclose(f);
2806 }
2807 }
2808 }
2809 }
2810
2811 int32_t gettilepagenumber(const char *prompt, int32_t initialval)
2812 {
2813 char buf[20];
2814 sprintf(buf,"%d",initialval);
2815 getnum_dlg[0].dp=(void *)prompt;
2816 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2817 getnum_dlg[2].dp=buf;
2818
2819 large_dialog(getnum_dlg);
2820
2821 int32_t ret = do_zqdialog(getnum_dlg,2);
2822
2823 if(ret==3)
2824 return atoi(buf);
2825
2826 return -1;
2827 }
2828
2829 int32_t gethexnumber(const char *prompt,int32_t initialval)
2830 {
2831 cancelgetnum=true;
2832 char buf[20];
2833 sprintf(buf,"%X",initialval);
2834 getnum_dlg[0].dp=(void *)prompt;
2835 getnum_dlg[0].dp2=get_zc_font(font_lfont);
2836 getnum_dlg[2].dp=(void *)buf;
2837
2838 large_dialog(getnum_dlg);
2839
2840 int32_t ret=do_zqdialog(getnum_dlg,2);
2841
2842 if(ret!=0&&ret!=4)
2843 {
2844 cancelgetnum=false;
2845 }
2846
2847 if(ret==3)
2848 return zc_xtoi(buf);
2849
2850 return initialval;
2851 }
2852
2853 void update_combo_cycling()
2854 {
2855 Map.update_combo_cycling();
2856 }
2857
2858 void update_freeform_combos()
2859 {
2860 Map.update_freeform_combos();
2861 }
2862
2863 bool layers_valid(mapscr *tempscr)
2864 {
2865 for(int32_t i=0; i<6; i++)
2866 {
2867 if(tempscr->layermap[i]>map_count)
2868 {
2869 return false;
2870 }
2871 }
2872
2873 return true;
2874 }
2875
2876 void fix_layers(mapscr *tempscr, bool showwarning)
2877 {
2878 char buf[80]="layers have been changed: ";
2879
2880 for(int32_t i=0; i<6; i++)
2881 {
2882 if(tempscr->layermap[i]>map_count)
2883 {
2884 strcat(buf, "%d ");
2885 sprintf(buf, buf, i+1);
2886 tempscr->layermap[i]=0;
2887 }
2888 }
2889
2890 if(showwarning)
2891 {
2892 jwin_alert("Invalid layers detected",
2893 "One or more layers on this screen used",
2894 "maps that do not exist. The settings of these",
2895 buf, "O&K", NULL, 'o', 0, get_zc_font(font_lfont));
2896 }
2897 }
2898
2899 extern const char *colorlist(int32_t index, int32_t *list_size);
2900
2901 static char autobackup_str_buf[32];
2902 const char *autobackuplist(int32_t index, int32_t *list_size)
2903 {
2904 if(index>=0)
2905 {
2906 bound(index,0,10);
2907
2908 if(index==0)
2909 {
2910 sprintf(autobackup_str_buf,"Disabled");
2911 }
2912 else
2913 {
2914 sprintf(autobackup_str_buf,"%2d",index);
2915 }
2916
2917 return autobackup_str_buf;
2918 }
2919
2920 *list_size=11;
2921 return NULL;
2922 }
2923
2924 static char autosave_str_buf[32];
2925 const char *autosavelist(int32_t index, int32_t *list_size)
2926 {
2927 if(index>=0)
2928 {
2929 bound(index,0,10);
2930
2931 if(index==0)
2932 {
2933 sprintf(autosave_str_buf,"Disabled");
2934 }
2935 else
2936 {
2937 sprintf(autosave_str_buf,"%2d Minute%c",index,index>1?'s':0);
2938 }
2939
2940 return autosave_str_buf;
2941 }
2942
2943 *list_size=11;
2944 return NULL;
2945 }
2946
2947 const char *autosavelist2(int32_t index, int32_t *list_size)
2948 {
2949 if(index>=0)
2950 {
2951 bound(index,0,9);
2952 sprintf(autosave_str_buf,"%2d",index+1);
2953 return autosave_str_buf;
2954 }
2955
2956 *list_size=10;
2957 return NULL;
2958 }
2959
2960
2961 static int32_t options_1_list[] =
2962 {
2963 // dialog control number
2964 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, -1
2965 };
2966
2967 static int32_t options_2_list[] =
2968 {
2969 // dialog control number
2970 50, 51, -1
2971 };
2972
2973 static int32_t options_3_list[] =
2974 {
2975 // dialog control number
2976 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, -1
2977 };
2978 static int32_t options_4_list[] =
2979 {
2980 57, 58, 59, 60,
2981 -1
2982 };
2983
2984 static TABPANEL options_tabs[] =
2985 {
2986 // (text)
2987 { (char *)" 1 ", D_SELECTED, options_1_list, 0, NULL },
2988 { (char *)" 2 ", 0, options_2_list, 0, NULL },
2989 { (char *)" 3 ", 0, options_3_list, 0, NULL },
2990 { (char *)" 4 ", 0, options_4_list, 0, NULL },
2991 { NULL, 0, NULL, 0, NULL }
2992 };
2993
2994 9 static ListData autobackup_list(autobackuplist, &font);
2995 9 static ListData autosave_list(autosavelist, &font);
2996 9 static ListData autosave_list2(autosavelist2, &font);
2997 9 static ListData color_list(colorlist, &font);
2998 9 static ListData snapshotformat_list(snapshotformatlist, &font);
2999 void init_ffpos();
3000
3001 const char *dm_names[dm_max]=
3002 {
3003 "Normal",
3004 "Relational", // Removed.
3005 "Dungeon", // Removed.
3006 "Alias",
3007 "Pool",
3008 "Auto"
3009 };
3010
3011 void fix_drawing_mode_menu()
3012 {
3013 drawing_mode_menu.select_only_uid(draw_mode);
3014 }
3015
3016 int32_t onDrawingMode()
3017 {
3018 draw_mode=(draw_mode+1)%dm_max;
3019 int dm_relational = 1;
3020 if ((int)draw_mode == dm_relational)
3021 draw_mode += 2;
3022 fix_drawing_mode_menu();
3023 restore_mouse();
3024 return D_O_K;
3025 }
3026
3027 int32_t onDrawingModeNormal()
3028 {
3029 draw_mode=dm_normal;
3030 fix_drawing_mode_menu();
3031 restore_mouse();
3032 return D_O_K;
3033 }
3034
3035 int32_t onDrawingModeAlias()
3036 {
3037 if(draw_mode==dm_alias)
3038 {
3039 return onDrawingModeNormal();
3040 }
3041
3042 draw_mode=dm_alias;
3043 alias_cset_mod=0;
3044 fix_drawing_mode_menu();
3045 restore_mouse();
3046 return D_O_K;
3047 }
3048
3049 int32_t onDrawingModePool()
3050 {
3051 if(draw_mode==dm_cpool)
3052 {
3053 return onDrawingModeNormal();
3054 }
3055
3056 draw_mode=dm_cpool;
3057 fix_drawing_mode_menu();
3058 restore_mouse();
3059 return D_O_K;
3060 }
3061
3062 int32_t onDrawingModeAuto()
3063 {
3064 if (draw_mode == dm_auto)
3065 {
3066 return onDrawingModeNormal();
3067 }
3068
3069 draw_mode = dm_auto;
3070 fix_drawing_mode_menu();
3071 restore_mouse();
3072 return D_O_K;
3073 }
3074
3075 int32_t onReTemplate()
3076 {
3077 if(jwin_alert("Confirm Overwrite","Apply NES Dungeon template to","all screens on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
3078 {
3079 Map.TemplateAll();
3080 refresh(rALL);
3081 }
3082
3083 return D_O_K;
3084 }
3085
3086 int32_t onUndo()
3087 {
3088 Map.UndoCommand();
3089 refresh(rALL);
3090 return D_O_K;
3091 }
3092
3093 int32_t onRedo()
3094 {
3095 Map.RedoCommand();
3096 refresh(rALL);
3097 return D_O_K;
3098 }
3099
3100 int32_t onCopy()
3101 {
3102 if(prv_mode)
3103 {
3104 Map.set_prvcmb(Map.get_prvcmb()==0?1:0);
3105
3106 init_ffpos();
3107
3108 return D_O_K;
3109 }
3110
3111 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3112 Map.Copy(screen);
3113 return D_O_K;
3114 }
3115
3116 int32_t onPaste()
3117 {
3118 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
3119 {
3120 if(CHECK_CTRL_CMD)
3121 return onPasteAllToAll();
3122 else return onPasteAll();
3123 }
3124 else if(CHECK_CTRL_CMD)
3125 return onPasteToAll();
3126 else
3127 {
3128 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3129 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartial, screen);
3130 }
3131 return D_O_K;
3132 }
3133
3134 int32_t onPasteAll()
3135 {
3136 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3137 Map.DoPasteScreenCommand(PasteCommandType::ScreenAll, screen);
3138 return D_O_K;
3139 }
3140
3141 int32_t onPasteToAll()
3142 {
3143 if(confirmBox("You are about to paste to all screens on the current map."))
3144 {
3145 Map.DoPasteScreenCommand(PasteCommandType::ScreenPartialToEveryScreen);
3146 }
3147 return D_O_K;
3148 }
3149
3150 int32_t onPasteAllToAll()
3151 {
3152 if(confirmBox("You are about to paste to all screens on the current map."))
3153 {
3154 Map.DoPasteScreenCommand(PasteCommandType::ScreenAllToEveryScreen);
3155 }
3156 return D_O_K;
3157 }
3158
3159 int32_t onPasteUnderCombo()
3160 {
3161 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3162 Map.DoPasteScreenCommand(PasteCommandType::ScreenUnderCombo, screen);
3163 return D_O_K;
3164 }
3165
3166 int32_t onPasteSecretCombos()
3167 {
3168 Map.DoPasteScreenCommand(PasteCommandType::ScreenSecretCombos);
3169 return D_O_K;
3170 }
3171
3172 int32_t onPasteFFCombos()
3173 {
3174 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3175 Map.DoPasteScreenCommand(PasteCommandType::ScreenFFCombos, screen);
3176 return D_O_K;
3177 }
3178
3179 int32_t onPasteWarps()
3180 {
3181 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3182 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarps, screen);
3183 return D_O_K;
3184 }
3185
3186 int32_t onPasteScreenData()
3187 {
3188 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3189 Map.DoPasteScreenCommand(PasteCommandType::ScreenData, screen);
3190 return D_O_K;
3191 }
3192
3193 int32_t onPasteWarpLocations()
3194 {
3195 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3196 Map.DoPasteScreenCommand(PasteCommandType::ScreenWarpLocations, screen);
3197 return D_O_K;
3198 }
3199
3200 int32_t onPasteDoors()
3201 {
3202 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3203 Map.DoPasteScreenCommand(PasteCommandType::ScreenDoors, screen);
3204 return D_O_K;
3205 }
3206
3207 int32_t onPasteLayers()
3208 {
3209 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3210 Map.DoPasteScreenCommand(PasteCommandType::ScreenLayers, screen);
3211 return D_O_K;
3212 }
3213
3214 int32_t onPastePalette()
3215 {
3216 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3217 Map.DoPasteScreenCommand(PasteCommandType::ScreenPalette, screen);
3218 return D_O_K;
3219 }
3220
3221 int32_t onPasteRoom()
3222 {
3223 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3224 Map.DoPasteScreenCommand(PasteCommandType::ScreenRoom, screen);
3225 return D_O_K;
3226 }
3227
3228 int32_t onPasteGuy()
3229 {
3230 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3231 Map.DoPasteScreenCommand(PasteCommandType::ScreenGuy, screen);
3232 return D_O_K;
3233 }
3234
3235 int32_t onPasteEnemies()
3236 {
3237 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3238 Map.DoPasteScreenCommand(PasteCommandType::ScreenEnemies, screen);
3239 return D_O_K;
3240 }
3241
3242 int32_t onDelete()
3243 {
3244 restore_mouse();
3245
3246 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
3247 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
3248 if(!(scr->valid&mVALID) || jwin_alert("Confirm Delete","Delete this screen?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3249 {
3250 Map.DoClearScreenCommand(screen);
3251 }
3252
3253 saved=false;
3254 return D_O_K;
3255 }
3256
3257 int32_t onDeleteMap()
3258 {
3259 if(jwin_alert("Confirm Delete","Clear this entire map?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3260 {
3261 Map.clearmap(false);
3262 refresh(rALL);
3263 saved=false;
3264 }
3265
3266 return D_O_K;
3267 }
3268
3269 int32_t onToggleDarkness()
3270 {
3271 Map.CurrScr()->flags^=4;
3272 refresh(rMAP+rMENU);
3273 saved=false;
3274 return D_O_K;
3275 }
3276
3277 int32_t onIncMap()
3278 {
3279 int32_t m=Map.getCurrMap();
3280 int32_t oldcolor=Map.getcolor();
3281 Map.setCurrMap(m+1>=map_count?0:m+1);
3282 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3283 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3284
3285 int32_t newcolor=Map.getcolor();
3286
3287 if(newcolor!=oldcolor)
3288 {
3289 rebuild_trans_table();
3290 }
3291
3292 refresh(rALL);
3293 return D_O_K;
3294 }
3295
3296 int32_t onDecMap()
3297 {
3298 int32_t m=Map.getCurrMap();
3299 int32_t oldcolor=Map.getcolor();
3300 Map.setCurrMap((m-1<0)?map_count-1:zc_min(m-1,map_count-1));
3301 // Map.setCurrScr(Map.getCurrScr()); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3302 Map.setlayertarget(); //Needed to refresh the screen info. -Z ( 26th March, 2019 )
3303
3304 int32_t newcolor=Map.getcolor();
3305
3306 if(newcolor!=oldcolor)
3307 {
3308 rebuild_trans_table();
3309 }
3310
3311 refresh(rALL);
3312 return D_O_K;
3313 }
3314
3315
3316 int32_t onDefault_Pals()
3317 {
3318 if(jwin_alert("Confirm Reset","Reset all palette data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3319 {
3320 saved=false;
3321
3322 if(!init_colordata(true, &header, &QMisc))
3323 {
3324 jwin_alert("Error","Palette reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3325 }
3326
3327 refresh_pal();
3328 }
3329
3330 return D_O_K;
3331 }
3332
3333 int32_t onDefault_Combos()
3334 {
3335 if(jwin_alert("Confirm Reset","Reset combo data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3336 {
3337 saved=false;
3338
3339 if(!init_combos(true, &header))
3340 {
3341 jwin_alert("Error","Combo reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3342 }
3343
3344 refresh(rALL);
3345 }
3346
3347 return D_O_K;
3348 }
3349
3350 int32_t onDefault_Items()
3351 {
3352 if(jwin_alert("Confirm Reset","Reset all items?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3353 {
3354 saved=false;
3355 reset_items(true, &header);
3356 }
3357
3358 return D_O_K;
3359 }
3360
3361 int32_t onDefault_Weapons()
3362 {
3363 if(jwin_alert("Confirm Reset","Reset weapon/misc. sprite data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3364 {
3365 saved=false;
3366 reset_wpns(true, &header);
3367 }
3368
3369 return D_O_K;
3370 }
3371
3372 int32_t onDefault_Guys()
3373 {
3374 if(jwin_alert("Confirm Reset","Reset all enemy/NPC data?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3375 {
3376 saved=false;
3377 reset_guys();
3378 }
3379
3380 return D_O_K;
3381 }
3382
3383
3384 int32_t onDefault_Tiles()
3385 {
3386 if(jwin_alert("Confirm Reset","Reset all tiles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3387 {
3388 saved=false;
3389
3390 if(!init_tiles(true, &header))
3391 {
3392 jwin_alert("Error","Tile reset failed.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
3393 }
3394
3395 refresh(rALL);
3396 }
3397
3398 return D_O_K;
3399 }
3400
3401 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2);
3402
3403 int32_t onDefault_SFX()
3404 {
3405 if(jwin_alert("Confirm Reset","Reset all sound effects?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3406 {
3407 saved=false;
3408 SAMPLE *temp_sample;
3409
3410 for(int32_t i=1; i<WAV_COUNT; i++)
3411 {
3412 temp_sample = (SAMPLE *)sfxdata[zc_min(i,Z35)].dat;
3413 change_sfx(&customsfxdata[i], temp_sample);
3414 sprintf(sfx_string[i],"s%03d",i);
3415
3416 if(i<Z35)
3417 strcpy(sfx_string[i], old_sfx_string[i-1]);
3418 set_bit(customsfxflag, i<Z35?1:0, i-1);
3419 }
3420 }
3421
3422 return D_O_K;
3423 }
3424
3425
3426 int32_t onDefault_MapStyles()
3427 {
3428 if(jwin_alert("Confirm Reset","Reset all map styles?", NULL, NULL, "Yes", "Cancel", 'y', 27,get_zc_font(font_lfont)) == 1)
3429 {
3430 saved=false;
3431 reset_mapstyles(true, &QMisc);
3432 }
3433
3434 return D_O_K;
3435 }
3436
3437 int onScrollScreen(int dir, bool warp)
3438 {
3439 Map.scroll(dir,warp);
3440 return D_O_K;
3441 }
3442
3443 int32_t onComboColLeft()
3444 {
3445 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3446 ;
3447 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3448 {
3449 First[current_combolist]-=1;
3450 clear_tooltip();
3451 refresh(rCOMBOS);
3452 }
3453 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3454 {
3455 combo_alistpos[current_comboalist]-=1;
3456 clear_tooltip();
3457 refresh(rCOMBOS);
3458 }
3459
3460 clear_keybuf();
3461 return D_O_K;
3462 }
3463
3464 int32_t onComboColRight()
3465 {
3466 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3467 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3468 ;
3469 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3470 {
3471 First[current_combolist]+=1;
3472 clear_tooltip();
3473 refresh(rCOMBOS);
3474 }
3475 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))&&(draw_mode==dm_alias))
3476 {
3477 combo_alistpos[current_comboalist]+=1;
3478 clear_tooltip();
3479 refresh(rCOMBOS);
3480 }
3481
3482 clear_keybuf();
3483 return D_O_K;
3484 }
3485
3486 int32_t onComboColUp()
3487 {
3488 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3489 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3490 ;
3491 else if((First[current_combolist]>0)&&(draw_mode!=dm_alias))
3492 {
3493 First[current_combolist]-=zc_min(First[current_combolist],sqr.w);
3494 clear_tooltip();
3495
3496 refresh(rCOMBOS);
3497 }
3498 else if((combo_alistpos[current_comboalist]>0)&&(draw_mode==dm_alias))
3499 {
3500 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],sqr.w);
3501 clear_tooltip();
3502 refresh(rCOMBOS);
3503 }
3504
3505 clear_keybuf();
3506 return D_O_K;
3507 }
3508
3509 int32_t onComboColDown()
3510 {
3511 auto& sqr = (draw_mode == dm_alias ? comboaliaslist[current_comboalist] : combolist[current_combolist]);
3512
3513 if(draw_mode==dm_cpool||draw_mode==dm_auto)
3514 ;
3515 else if((First[current_combolist]<(MAXCOMBOS-(sqr.w*sqr.h)))&&(draw_mode!=dm_alias))
3516 {
3517 First[current_combolist]+=zc_min((MAXCOMBOS-sqr.w)-First[current_combolist],sqr.w);
3518 clear_tooltip();
3519 refresh(rCOMBOS);
3520 }
3521 else if((combo_alistpos[current_comboalist]<(MAXCOMBOALIASES-(comboaliaslist[0].w*comboaliaslist[0].h)))&&(draw_mode==dm_alias))
3522 {
3523 combo_alistpos[current_comboalist]+=zc_min((MAXCOMBOALIASES-sqr.w)-combo_alistpos[current_comboalist],sqr.w);
3524 clear_tooltip();
3525 refresh(rCOMBOS);
3526 }
3527
3528 clear_keybuf();
3529 return D_O_K;
3530 }
3531
3532 void scrollup(int j)
3533 {
3534 switch(draw_mode)
3535 {
3536 case dm_alias:
3537 {
3538 auto& sqr = comboaliaslist[j];
3539 if(combo_alistpos[j]>0)
3540 {
3541 if(CHECK_CTRL_CMD)
3542 {
3543 combo_alistpos[j]=0;
3544 clear_tooltip();
3545 }
3546 else
3547 {
3548 combo_alistpos[j]-=zc_min(combo_alistpos[j],(sqr.w*sqr.h));
3549 clear_tooltip();
3550 }
3551
3552 refresh(rCOMBOS);
3553 }
3554 break;
3555 }
3556 case dm_cpool:
3557 {
3558 auto& sqr = comboaliaslist[j];
3559 if(combo_pool_listpos[j]>0)
3560 {
3561 if(CHECK_CTRL_CMD)
3562 {
3563 combo_pool_listpos[j]=0;
3564 clear_tooltip();
3565 }
3566 else
3567 {
3568 combo_pool_listpos[j]-=zc_min(combo_pool_listpos[j],(sqr.w*sqr.h));
3569 clear_tooltip();
3570 }
3571
3572 refresh(rCOMBOS);
3573 }
3574 break;
3575 }
3576 case dm_auto:
3577 {
3578 auto& sqr = comboaliaslist[j];
3579 if (combo_auto_listpos[j] > 0)
3580 {
3581 if (CHECK_CTRL_CMD)
3582 {
3583 combo_auto_listpos[j] = 0;
3584 clear_tooltip();
3585 }
3586 else
3587 {
3588 combo_auto_listpos[j] -= zc_min(combo_auto_listpos[j], (sqr.w * sqr.h));
3589 clear_tooltip();
3590 }
3591
3592 refresh(rCOMBOS);
3593 }
3594 break;
3595 }
3596 default:
3597 {
3598 auto& sqr = combolist[j];
3599 if(First[j]>0)
3600 {
3601 if(CHECK_CTRL_CMD)
3602 {
3603 First[j]-=zc_min(First[j],256);
3604 clear_tooltip();
3605 }
3606 else
3607 {
3608 First[j]-=zc_min(First[j],(sqr.w*sqr.h));
3609 clear_tooltip();
3610 }
3611
3612 refresh(rCOMBOS);
3613 }
3614 break;
3615 }
3616 }
3617 }
3618 void scrolldown(int j)
3619 {
3620 switch(draw_mode)
3621 {
3622 case dm_alias:
3623 {
3624 auto& sqr = comboaliaslist[j];
3625 if(combo_alistpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3626 {
3627 if(CHECK_CTRL_CMD)
3628 {
3629 combo_alistpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3630 clear_tooltip();
3631 }
3632 else
3633 {
3634 combo_alistpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_alistpos[j]+(sqr.w*sqr.h));
3635 clear_tooltip();
3636 }
3637
3638 refresh(rCOMBOS);
3639 }
3640 break;
3641 }
3642 case dm_cpool:
3643 {
3644 auto& sqr = comboaliaslist[j];
3645 if(combo_pool_listpos[j]<(MAXCOMBOALIASES-(sqr.w*sqr.h)))
3646 {
3647 if(CHECK_CTRL_CMD)
3648 {
3649 combo_pool_listpos[j]=MAXCOMBOALIASES-(sqr.w*sqr.h);
3650 clear_tooltip();
3651 }
3652 else
3653 {
3654 combo_pool_listpos[j]=zc_min((MAXCOMBOALIASES-(sqr.w*sqr.h)),combo_pool_listpos[j]+(sqr.w*sqr.h));
3655 clear_tooltip();
3656 }
3657
3658 refresh(rCOMBOS);
3659 }
3660 break;
3661 }
3662 case dm_auto:
3663 {
3664 auto& sqr = comboaliaslist[j];
3665 if (combo_auto_listpos[j] < (MAXCOMBOALIASES - (sqr.w * sqr.h)))
3666 {
3667 if (CHECK_CTRL_CMD)
3668 {
3669 combo_auto_listpos[j] = MAXCOMBOALIASES - (sqr.w * sqr.h);
3670 clear_tooltip();
3671 }
3672 else
3673 {
3674 combo_auto_listpos[j] = zc_min((MAXCOMBOALIASES - (sqr.w * sqr.h)), combo_pool_listpos[j] + (sqr.w * sqr.h));
3675 clear_tooltip();
3676 }
3677
3678 refresh(rCOMBOS);
3679 }
3680 break;
3681 }
3682 default:
3683 {
3684 auto& sqr = combolist[j];
3685 if(First[j]<(MAXCOMBOS-(sqr.w*sqr.h)))
3686 {
3687 if(CHECK_CTRL_CMD)
3688 {
3689 First[j]=zc_min((MAXCOMBOS-sqr.w*sqr.h),First[j]+256);
3690 clear_tooltip();
3691 }
3692 else
3693 {
3694 First[j]=zc_min((MAXCOMBOS-(sqr.w*sqr.h)),First[j]+(sqr.w*sqr.h));
3695 clear_tooltip();
3696 }
3697
3698 refresh(rCOMBOS);
3699 }
3700 break;
3701 }
3702 }
3703 }
3704
3705 int32_t onPgUp()
3706 {
3707 switch(draw_mode)
3708 {
3709 case dm_alias:
3710 scrollup(current_comboalist);
3711 break;
3712 case dm_cpool:
3713 scrollup(current_cpoollist);
3714 break;
3715 case dm_auto:
3716 scrollup(current_cautolist);
3717 break;
3718 default:
3719 scrollup(current_combolist);
3720 break;
3721 }
3722 return D_O_K;
3723 }
3724
3725 int32_t onPgDn()
3726 {
3727 switch(draw_mode)
3728 {
3729 case dm_alias:
3730 scrolldown(current_comboalist);
3731 break;
3732 case dm_cpool:
3733 scrolldown(current_cpoollist);
3734 break;
3735 case dm_auto:
3736 scrolldown(current_cautolist);
3737 break;
3738 default:
3739 scrolldown(current_combolist);
3740 break;
3741 }
3742 return D_O_K;
3743 }
3744
3745 int32_t onIncreaseCSet()
3746 {
3747 if(draw_mode!=dm_alias)
3748 {
3749 CSet=wrap(CSet+1,0,13);
3750 refresh(rCOMBOS+rMENU+rCOMBO);
3751 }
3752 else
3753 {
3754 alias_cset_mod=wrap(alias_cset_mod+1,0,13);
3755 }
3756 return D_O_K;
3757 }
3758
3759 int32_t onDecreaseCSet()
3760 {
3761 if(draw_mode!=dm_alias)
3762 {
3763 CSet=wrap(CSet-1,0,13);
3764 refresh(rCOMBOS+rMENU+rCOMBO);
3765 }
3766 else
3767 {
3768 alias_cset_mod=wrap(alias_cset_mod-1,0,13);
3769 }
3770 return D_O_K;
3771 }
3772
3773 int32_t onGotoPage()
3774 {
3775 if (draw_mode==dm_alias)
3776 {
3777 static const int PER_PAGE = 260;
3778 if(optional<int> v = call_get_num("Scroll to Alias Page", 0, MAXCOMBOALIASES/PER_PAGE-1, 0))
3779 combo_alistpos[current_comboalist] = *v*PER_PAGE;
3780 }
3781 else if (draw_mode==dm_cpool)
3782 {
3783 static const int PER_PAGE = 260;
3784 if(optional<int> v = call_get_num("Scroll to Combo Pool Page", 0, MAXCOMBOPOOLS/PER_PAGE-1, 0))
3785 combo_pool_listpos[current_cpoollist] = *v*PER_PAGE;
3786 }
3787 else if (draw_mode == dm_auto)
3788 {
3789 static const int PER_PAGE = 260;
3790 if(optional<int> v = call_get_num("Scroll to Auto Combo Page", 0, MAXAUTOCOMBOS/PER_PAGE-1, 0))
3791 combo_auto_listpos[current_cautolist] = *v*PER_PAGE;
3792 }
3793 else
3794 {
3795 static const int PER_PAGE = 256;
3796 if(optional<int> v = call_get_num("Scroll to Combo Page", 0, MAXCOMBOS/PER_PAGE-1, 0))
3797 First[current_combolist] = *v*PER_PAGE;
3798 }
3799
3800 return D_O_K;
3801 }
3802
3803 static char track_number_str_buf[MIDI_TRACK_BUFFER_SIZE] = {0};
3804 const char *tracknumlist(int32_t index, int32_t *list_size)
3805 {
3806 //memset(track_number_str_buf,0,50);
3807 if(index>=0)
3808 {
3809 bound(index,0,255);
3810 std::string name = zcmusic_get_track_name(zcmusic, index);
3811 sprintf(track_number_str_buf,"%02d %s",index+1, name.c_str());
3812 return track_number_str_buf;
3813 }
3814
3815 *list_size=zcmusic_get_tracks(zcmusic);
3816 return NULL;
3817 }
3818
3819 9 static ListData tracknum_list(tracknumlist, &font);
3820
3821 static DIALOG change_track_dlg[] =
3822 {
3823 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
3824 9 { jwin_win_proc, 60-12, 40, 200-16, 72, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Track", NULL, NULL },
3825 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
3826 9 { jwin_droplist_proc, 72-12, 60+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &tracknum_list, NULL, NULL },
3827 9 { jwin_button_proc, 70, 87, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
3828 9 { jwin_button_proc, 150, 87, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
3829 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
3830 };
3831 // return list_dlg[2].d1;
3832
3833 int32_t changeTrack()
3834 {
3835 restore_mouse();
3836 change_track_dlg[0].dp2=get_zc_font(font_lfont);
3837 change_track_dlg[2].d1=gme_track;
3838
3839 large_dialog(change_track_dlg);
3840
3841 if(do_zqdialog(change_track_dlg,2)==3)
3842 {
3843 gme_track=change_track_dlg[2].d1;
3844 zcmusic_change_track(zcmusic, gme_track);
3845 }
3846
3847 return D_O_K;
3848 }
3849
3850 void set_media_tunes()
3851 {
3852 media_menu.select_uid(MENUID_MEDIA_TUNES, true);
3853 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
3854 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3855 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3856
3857 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3858 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3859 }
3860
3861 int32_t playMusic()
3862 {
3863 char *ext;
3864 bool ismidi=false;
3865 char allmusic_types[256];
3866 sprintf(allmusic_types, "%s;mid", zcmusic_types);
3867
3868 if(prompt_for_existing_file_compat("Load Music",(char*)allmusic_types,NULL,midipath,false))
3869 {
3870 strcpy(midipath,temppath);
3871
3872 ext=get_extension(midipath);
3873
3874 if(
3875 (stricmp(ext,"ogg")==0)||
3876 (stricmp(ext,"mp3")==0)||
3877 (stricmp(ext,"it")==0)||
3878 (stricmp(ext,"xm")==0)||
3879 (stricmp(ext,"s3m")==0)||
3880 (stricmp(ext,"mod")==0)||
3881 (stricmp(ext,"spc")==0)||
3882 (stricmp(ext,"gym")==0)||
3883 (stricmp(ext,"nsf")==0)||
3884 (stricmp(ext,"gbs")==0)||
3885 (stricmp(ext,"vgm")==0)
3886 )
3887 {
3888 ismidi=false;
3889 }
3890 else if((stricmp(ext,"mid")==0))
3891 {
3892 ismidi=true;
3893 }
3894 else
3895 {
3896 return D_O_K;
3897 }
3898
3899 zc_stop_midi();
3900
3901 if(zcmusic != NULL)
3902 {
3903 zcmusic_stop(zcmusic);
3904 zcmusic_unload_file(zcmusic);
3905 zcmusic = NULL;
3906 zcmixer->newtrack = NULL;
3907 }
3908
3909 if(ismidi)
3910 {
3911 packfile_password("");
3912 if((song=load_midi(midipath))!=NULL)
3913 {
3914 if(zc_play_midi(song,true)==0)
3915 {
3916 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3917 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3918 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3919 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3920
3921 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
3922 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
3923 }
3924 }
3925 }
3926 else
3927 {
3928 gme_track=0;
3929 zcmusic = (ZCMUSIC*)zcmusic_load_file(midipath);
3930
3931 if(zcmusic!=NULL)
3932 {
3933 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
3934 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, true);
3935 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
3936 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
3937
3938 bool distrack = zcmusic_get_tracks(zcmusic)<2;
3939 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, distrack);
3940 disable_hotkey(ZQKEY_CHANGE_TRACK, distrack);
3941
3942 zcmusic_play(zcmusic, midi_volume);
3943 }
3944 }
3945 }
3946
3947 return D_O_K;
3948 }
3949
3950 int32_t playZCForever()
3951 {
3952 stopMusic();
3953
3954 zcmusic = zcmusic_load_file("assets/zc/ZC_Forever_HD.mp3");
3955 if (zcmusic)
3956 {
3957 zcmusic_play(zcmusic, midi_volume);
3958 set_media_tunes();
3959 }
3960 return D_O_K;
3961 }
3962
3963 // It took awhile to get these values right, so no meddlin'!
3964 int32_t playTune1()
3965 {
3966 return playTune(0);
3967 }
3968 int32_t playTune2()
3969 {
3970 return playTune(81);
3971 }
3972 int32_t playTune3()
3973 {
3974 return playTune(233);
3975 }
3976 int32_t playTune4()
3977 {
3978 return playTune(553);
3979 }
3980 int32_t playTune5()
3981 {
3982 return playTune(814);
3983 }
3984 int32_t playTune6()
3985 {
3986 return playTune(985);
3987 }
3988 int32_t playTune7()
3989 {
3990 return playTune(1153);
3991 }
3992 int32_t playTune8()
3993 {
3994 return playTune(1333);
3995 }
3996 int32_t playTune9()
3997 {
3998 return playTune(1556);
3999 }
4000 int32_t playTune10()
4001 {
4002 return playTune(1801);
4003 }
4004 int32_t playTune11()
4005 {
4006 return playTune(2069);
4007 }
4008 int32_t playTune12()
4009 {
4010 return playTune(2189);
4011 }
4012 int32_t playTune13()
4013 {
4014 return playTune(2569);
4015 }
4016 int32_t playTune14()
4017 {
4018 return playTune(2753);
4019 }
4020 int32_t playTune15()
4021 {
4022 return playTune(2856);
4023 }
4024 int32_t playTune16()
4025 {
4026 return playTune(3042);
4027 }
4028 int32_t playTune17()
4029 {
4030 return playTune(3125);
4031 }
4032 int32_t playTune18()
4033 {
4034 return playTune(3217);
4035 }
4036 int32_t playTune19()
4037 {
4038 return playTune(3296);
4039 }
4040
4041 int32_t playTune(int32_t pos)
4042 {
4043 zc_stop_midi();
4044
4045 if(zcmusic != NULL)
4046 {
4047 zcmusic_stop(zcmusic);
4048 zcmusic_unload_file(zcmusic);
4049 zcmusic = NULL;
4050 zcmixer->newtrack = NULL;
4051 }
4052
4053 if(zc_play_midi(asset_tunes_midi,true)==0)
4054 {
4055 zc_midi_seek(pos);
4056 set_media_tunes();
4057 }
4058
4059 return D_O_K;
4060 }
4061
4062 int32_t stopMusic()
4063 {
4064 zc_stop_midi();
4065
4066 if(zcmusic != NULL)
4067 {
4068 zcmusic_stop(zcmusic);
4069 zcmusic_unload_file(zcmusic);
4070 zcmusic = NULL;
4071 zcmixer->newtrack = NULL;
4072 }
4073
4074 media_menu.select_uid(MENUID_MEDIA_TUNES, false);
4075 media_menu.select_uid(MENUID_MEDIA_PLAYMUSIC, false);
4076 disable_hotkey(ZQKEY_AMBIENT_MUSIC, false);
4077 disable_hotkey(ZQKEY_PLAY_MUSIC, false);
4078
4079 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
4080 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
4081 return D_O_K;
4082 }
4083
4084 static int32_t gamemisc1_list[] =
4085 {
4086 5,6,7,8,
4087 9,10,11,12,
4088
4089 37,38,39,40,
4090 41,42,43,44,
4091
4092 71,72,73,74,
4093 75,76,77,78,
4094
4095 -1
4096 };
4097
4098 static int32_t gamemisc2_list[] =
4099 {
4100 13,14,15,16,
4101 17,18,19,20,
4102
4103 45,46,47,48,
4104 49,50,51,52,
4105
4106 79,80,81,82,
4107 83,84,85,86,
4108
4109 -1
4110 };
4111
4112 static int32_t gamemisc3_list[] =
4113 {
4114 21,22,23,24,
4115 25,26,27,28,
4116
4117 53,54,55,56,
4118 57,58,59,60,
4119
4120 87,88,89,90,
4121 91,92,93,94,
4122
4123 -1
4124 };
4125
4126 static int32_t gamemisc4_list[] =
4127 {
4128 29,30,31,32,
4129 33,34,35,36,
4130
4131 61,62,63,64,
4132 65,66,67,68,
4133
4134 95,96,97,98,
4135 99,100,101,102,
4136
4137 -1
4138 };
4139
4140 static TABPANEL gamemisc_tabs[] =
4141 {
4142 // (text)
4143 { (char *)" Misc[0-7] ", D_SELECTED, gamemisc1_list, 0, NULL },
4144 { (char *)" Misc[8-15] ", 0, gamemisc2_list, 0, NULL },
4145 { (char *)" Misc[16-23] ", 0, gamemisc3_list, 0, NULL },
4146 { (char *)" Misc[24-31] ", 0, gamemisc4_list, 0, NULL },
4147 { NULL, 0, NULL, 0, NULL }
4148 };
4149
4150 //to do: Make string boxes larger, and split into two tabs.
4151 static DIALOG gamemiscarray_dlg[] =
4152 {
4153 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
4154
4155 { jwin_win_proc, 0, 10, 310, 224, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Game->Misc[]", NULL, NULL },
4156 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4157 { jwin_tab_proc, 3, 26, 304, 174, vc(14), vc(1), 0, 0, 1, 0, (void *) gamemisc_tabs, NULL, (void *)gamemiscarray_dlg },
4158 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4159 { d_dummy_proc, 240, 144, 40, 8, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
4160
4161 //5
4162 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4163 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4164 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4165 //8
4166 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4167 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4168 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4169 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4170 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4171 //13
4172 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4173 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4174 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4175 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4176 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4177 //18
4178 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4179 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4180 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4181 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4182 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4183 //23
4184 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4185 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4186 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4187 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4188 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4189 //28
4190 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4191 { jwin_edit_proc, 8, 42, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4192 { jwin_edit_proc, 8, 42+20, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4193 { jwin_edit_proc, 8, 42+40, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4194 { jwin_edit_proc, 8, 42+60, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4195 //33
4196 { jwin_edit_proc, 8, 42+80, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4197 { jwin_edit_proc, 8, 42+100, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4198 { jwin_edit_proc, 8, 42+120, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4199 { jwin_edit_proc, 8, 42+140, 100-12, 16, vc(12), vc(1), 0, 0, 64, 0, NULL, NULL, NULL },
4200 //37
4201 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4202 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4203 //39
4204 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4205 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4206 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4207 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4208 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4209 //44
4210 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4211 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4212 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4213
4214 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4215 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4216 //49
4217 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4218 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4219 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4220 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4221 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4222 //54
4223 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4224 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4225 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4226 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4227 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4228 //59
4229 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4230 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4231 { jwin_numedit_swap_zsint_proc, 96, 42, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4232 { jwin_numedit_swap_zsint_proc, 96, 42+20, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4233 { jwin_numedit_swap_zsint_proc, 96, 42+40, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4234 //64
4235 { jwin_numedit_swap_zsint_proc, 96, 42+60, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4236 { jwin_numedit_swap_zsint_proc, 96, 42+80, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4237 { jwin_numedit_swap_zsint_proc, 96, 42+100, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4238 { jwin_numedit_swap_zsint_proc, 96, 42+120, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4239 { jwin_numedit_swap_zsint_proc, 96, 42+140, 60, 16, vc(12), vc(1), 0, 0, 12, 0, NULL, NULL, NULL },
4240 //69
4241 { jwin_button_proc, 70, 204, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4242 { jwin_button_proc, 170, 204, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4243
4244 //71
4245 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4246 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4247 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4248 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4249 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4250 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4251 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4252 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4253 //79
4254 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4255 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4256 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4257 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4258 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4259 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4260 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4261 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4262 //87
4263 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4264 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4265 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4266 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4267 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4268 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4269 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4270 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4271 //95
4272 { jwin_swapbtn_proc, 156, 42, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4273 { jwin_swapbtn_proc, 156, 62, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4274 { jwin_swapbtn_proc, 156, 82, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4275 { jwin_swapbtn_proc, 156, 102, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4276 { jwin_swapbtn_proc, 156, 122, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4277 { jwin_swapbtn_proc, 156, 142, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4278 { jwin_swapbtn_proc, 156, 162, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4279 { jwin_swapbtn_proc, 156, 182, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4280
4281 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4282 };
4283
4284 // +----------+
4285 // | |
4286 // | View Pic |
4287 // | |
4288 // | |
4289 // | |
4290 // +----------+
4291
4292 BITMAP *pic=NULL;
4293 BITMAP *bmap=NULL;
4294 PALETTE picpal;
4295 PALETTE mappal;
4296 int32_t picx=0,picy=0,mapx=0,mapy=0,pblack,pwhite;
4297
4298 double picscale=1.0,mapscale=1.0;
4299 bool vp_showpal=true, vp_showsize=true, vp_center=true;
4300
4301 //INLINE int32_t pal_sum(RGB p) { return p.r + p.g + p.b; }
4302
4303 void get_bw(RGB *pal,int32_t &black,int32_t &white)
4304 {
4305 black=white=1;
4306
4307 for(int32_t i=1; i<256; i++)
4308 {
4309 if(pal_sum(pal[i])<pal_sum(pal[black]))
4310 black=i;
4311
4312 if(pal_sum(pal[i])>pal_sum(pal[white]))
4313 white=i;
4314 }
4315 }
4316
4317 void draw_bw_mouse(int32_t white, int32_t old_mouse, int32_t new_mouse)
4318 {
4319 blit(mouse_bmp[old_mouse][0],mouse_bmp[new_mouse][0],0,0,0,0,16,16);
4320
4321 for(int32_t y=0; y<16; y++)
4322 {
4323 for(int32_t x=0; x<16; x++)
4324 {
4325 if(getpixel(mouse_bmp[new_mouse][0],x,y)!=0)
4326 {
4327 putpixel(mouse_bmp[new_mouse][0],x,y,white);
4328 }
4329 }
4330 }
4331 }
4332
4333 int32_t load_the_pic(BITMAP **dst, PALETTE dstpal)
4334 {
4335 PALETTE temppal;
4336
4337 for(int32_t i=0; i<256; i++)
4338 {
4339 temppal[i]=dstpal[i];
4340 dstpal[i]=RAMpal[i];
4341 }
4342
4343 // set up the new palette
4344 for(int32_t i=0; i<64; i++)
4345 {
4346 dstpal[i].r = i;
4347 dstpal[i].g = i;
4348 dstpal[i].b = i;
4349 }
4350
4351 zc_set_palette(dstpal);
4352
4353 BITMAP *graypic = create_bitmap_ex(8,screen->w,screen->h);
4354 int32_t _w = screen->w-1;
4355 int32_t _h = screen->h-1;
4356
4357 // gray scale the current frame
4358 for(int32_t y=0; y<_h; y++)
4359 {
4360 for(int32_t x=0; x<_w; x++)
4361 {
4362 int32_t c = screen->line[y][x];
4363 int32_t gray = zc_min((temppal[c].r*42 + temppal[c].g*75 + temppal[c].b*14) >> 7, 63);
4364 graypic->line[y][x] = gray;
4365 }
4366 }
4367
4368 blit(graypic,screen,0,0,0,0,screen->w,screen->h);
4369 destroy_bitmap(graypic);
4370 #ifdef __GNUC__
4371 #pragma GCC diagnostic ignored "-Wformat-overflow"
4372 #endif
4373 char extbuf[2][80];
4374 memset(extbuf[0],0,80);
4375 memset(extbuf[1],0,80);
4376 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4377 strcpy(extbuf[1], snapshotformat_str[0][1]);
4378
4379 for(int32_t i=1; i<ssfmtMAX; ++i)
4380 {
4381 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4382 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4383 }
4384
4385 sprintf(extbuf[0], "%s)", extbuf[0]);
4386 #ifdef __GNUC__
4387 #pragma GCC diagnostic pop
4388 #endif
4389
4390 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4391
4392 if(!gotit)
4393 {
4394 zc_set_palette(temppal);
4395 get_palette(dstpal);
4396 return 1;
4397 }
4398
4399 strcpy(imagepath,temppath);
4400
4401 if(*dst)
4402 {
4403 destroy_bitmap(*dst);
4404 }
4405
4406 for(int32_t i=0; i<256; i++)
4407 {
4408 dstpal[i].r = 0;
4409 dstpal[i].g = 0;
4410 dstpal[i].b = 0;
4411 }
4412
4413 *dst = load_bitmap(imagepath,picpal);
4414
4415 if(!*dst)
4416 {
4417 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4418 return 2;
4419 }
4420
4421 // get_bw(picpal,pblack,pwhite);
4422 // draw_bw_mouse(pwhite);
4423 // gui_bg_color = pblack;
4424 // gui_fg_color = pwhite;
4425
4426 if(vp_center)
4427 {
4428 picx=picy=0;
4429 }
4430 else
4431 {
4432 picx=(*dst)->w-zq_screen_w;
4433 picy=(*dst)->h-zq_screen_h;
4434 }
4435
4436 return 0;
4437 }
4438 int load_the_pic_new(BITMAP **dst, PALETTE dstpal)
4439 {
4440 #ifdef __GNUC__
4441 #pragma GCC diagnostic ignored "-Wformat-overflow"
4442 #endif
4443 char extbuf[2][80];
4444 memset(extbuf[0],0,80);
4445 memset(extbuf[1],0,80);
4446 sprintf(extbuf[0], "View Image (%s", snapshotformat_str[0][1]);
4447 strcpy(extbuf[1], snapshotformat_str[0][1]);
4448
4449 for(int32_t i=1; i<ssfmtMAX; ++i)
4450 {
4451 sprintf(extbuf[0], "%s, %s", extbuf[0], snapshotformat_str[i][1]);
4452 sprintf(extbuf[1], "%s;%s", extbuf[1], snapshotformat_str[i][1]);
4453 }
4454
4455 sprintf(extbuf[0], "%s)", extbuf[0]);
4456 #ifdef __GNUC__
4457 #pragma GCC diagnostic pop
4458 #endif
4459
4460 int32_t gotit = prompt_for_existing_file_compat(extbuf[0],extbuf[1],NULL,imagepath,true);
4461
4462 if(!gotit)
4463 return 1;
4464
4465 strcpy(imagepath,temppath);
4466
4467 if(*dst)
4468 destroy_bitmap(*dst);
4469
4470 for(int32_t i=0; i<256; i++)
4471 {
4472 dstpal[i].r = 0;
4473 dstpal[i].g = 0;
4474 dstpal[i].b = 0;
4475 }
4476
4477 *dst = load_bitmap(imagepath,dstpal);
4478
4479 if(!*dst)
4480 {
4481 jwin_alert("Error","Error loading image:",imagepath,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4482 return 2;
4483 }
4484
4485 if(vp_center)
4486 {
4487 picx=picy=0;
4488 }
4489 else
4490 {
4491 picx=(*dst)->w-zq_screen_w;
4492 picy=(*dst)->h-zq_screen_h;
4493 }
4494
4495 return 0;
4496 }
4497
4498 int32_t saveMapAsImage(ALLEGRO_BITMAP* bitmap)
4499 {
4500 char buf[200];
4501 int32_t num=0;
4502
4503 do
4504 {
4505 snprintf(buf, 200, "%szquest_map%05d.%s", get_snap_str(), ++num, snapshotformat_str[SnapshotFormat][1]);
4506 buf[199]='\0';
4507 }
4508 while(num<99999 && exists(buf));
4509
4510 if (!al_save_bitmap(buf, bitmap))
4511 InfoDialog("Error", "Failed to save map image").show();
4512
4513 return D_O_K;
4514 }
4515
4516 int32_t onViewPic()
4517 {
4518 return launchPicViewer(&pic,picpal,&picx,&picy,&picscale,false);
4519 }
4520
4521
4522 class MapViewRTI : public RenderTreeItem
4523 {
4524 public:
4525
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 9 times.
9 MapViewRTI(): RenderTreeItem("map_view")
4526 9 {
4527 9 }
4528
4529 int bw, bh, sw, sh, flags;
4530
4531 private:
4532 void render(bool bitmap_resized)
4533 {
4534 MapCursor previous_cursor = Map.getCursor();
4535 Map.setViewSize(1);
4536
4537 BITMAP* bmap4_single = create_bitmap_ex(8,256,176);
4538 set_bitmap_create_flags(true);
4539 ALLEGRO_BITMAP* bmap5_single = al_create_bitmap(256,176);
4540 for(int32_t y=0; y<8; y++)
4541 {
4542 for(int32_t x=0; x<16; x++)
4543 {
4544 clear_bitmap(bmap4_single);
4545 Map.setCurrScr(y*16+x);
4546 Map.draw(bmap4_single, 0, 0, flags, -1, y*16+x, -1);
4547 stretch_blit(bmap4_single, bmap4_single, 0, 0, 0, 0, 256, 176, 256, 176);
4548 all_render_a5_bitmap(bmap4_single, bmap5_single);
4549 al_draw_scaled_bitmap(bmap5_single, 0, 0, 256, 176, sw * x, sh * y, sw, sh, 0);
4550 }
4551 }
4552
4553 Map.setCursor(previous_cursor);
4554 destroy_bitmap(bmap4_single);
4555 al_destroy_bitmap(bmap5_single);
4556 }
4557 };
4558 9 static MapViewRTI rti_map_view;
4559
4560 int32_t launchPicViewer(BITMAP **pictoview, PALETTE pal, int32_t *px2, int32_t *py2, double *scale2, bool isviewingmap, bool skipmenu)
4561 {
4562 restore_mouse();
4563 BITMAP *buf;
4564 bool done=false, redraw=true;
4565
4566 popup_zqdialog_start();
4567
4568 // Always call load_the_map() when viewing the map.
4569 if((!*pictoview || isviewingmap) && (isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)))
4570 {
4571 zc_set_palette(RAMpal);
4572 popup_zqdialog_end();
4573 close_the_map();
4574 return D_O_K;
4575 }
4576
4577 get_bw(pal,pblack,pwhite);
4578
4579 int32_t oldfgcolor = gui_fg_color;
4580 int32_t oldbgcolor = gui_bg_color;
4581
4582 buf = create_bitmap_ex(8,zq_screen_w,zq_screen_h);
4583
4584 if(!buf)
4585 {
4586 jwin_alert("Error","Error creating temp bitmap",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
4587 popup_zqdialog_end();
4588 close_the_map();
4589 return D_O_K;
4590 }
4591
4592 static LegacyBitmapRTI viewer_overlay_rti("viewer_overlay");
4593 viewer_overlay_rti.set_size(buf->w, buf->h);
4594 viewer_overlay_rti.a4_bitmap = buf;
4595 viewer_overlay_rti.transparency_index = 15;
4596 get_root_rti()->add_child(&viewer_overlay_rti);
4597
4598 zc_set_palette(pal);
4599
4600 if(isviewingmap)
4601 {
4602 int sw = rti_map_view.width / 16;
4603 int sh = rti_map_view.height / 8;
4604 int scr = Map.getCurrScr();
4605 if (scr >= 0x00 && scr <= 0x7F)
4606 {
4607 int dw = al_get_display_width(all_get_display()) / get_root_rti()->get_transform().xscale;
4608 int dh = al_get_display_height(all_get_display()) / get_root_rti()->get_transform().yscale;
4609 mapx = (-(scr % 16) * sw - sw/2 + dw/2);
4610 mapy = (-(scr / 16) * sh - sh/2 + dh/2);
4611 }
4612 }
4613
4614 int w, h;
4615 if (isviewingmap)
4616 {
4617 w = rti_map_view.width;
4618 h = rti_map_view.height;
4619 }
4620 else
4621 {
4622 w = (*pictoview)->w;
4623 h = (*pictoview)->h;
4624 }
4625
4626 do
4627 {
4628 if (isviewingmap)
4629 {
4630 float scale = *scale2;
4631 int dw = al_get_display_width(all_get_display()) / get_root_rti()->get_transform().xscale;
4632 int dh = al_get_display_height(all_get_display()) / get_root_rti()->get_transform().yscale;
4633 mapx = std::max(mapx, (int)(-w*scale + dw));
4634 mapy = std::max(mapy, (int)(-h*scale + dh));
4635 mapx = std::min(mapx, 0);
4636 mapy = std::min(mapy, 0);
4637 rti_map_view.set_transform({mapx, mapy, scale, scale});
4638 }
4639
4640 if(redraw)
4641 {
4642 clear_to_color(buf,15);
4643
4644 if (!isviewingmap)
4645 stretch_blit(*pictoview, buf, 0, 0, w, h,
4646 int32_t(zq_screen_w + (*px2 - w) * *scale2) / 2, int32_t(zq_screen_h + (*py2 - h) * *scale2) / 2,
4647 int32_t(w * *scale2), int32_t(h * *scale2));
4648
4649 if(vp_showpal)
4650 for(int32_t i=0; i<256; i++)
4651 rectfill(buf,((i&15)<<2)+zq_screen_w-64,((i>>4)<<2)+zq_screen_h-64,((i&15)<<2)+zq_screen_w-64+3,((i>>4)<<2)+zq_screen_h-64+3,i);
4652
4653 if(vp_showsize)
4654 {
4655 textprintf_ex(buf,font,0,zq_screen_h-8,pwhite,pblack,"%dx%d %.2f%%",w,h,*scale2*100.0);
4656 }
4657
4658 if (!isviewingmap)
4659 blit(buf,screen,0,0,0,0,zq_screen_w,zq_screen_h);
4660 redraw=false;
4661 }
4662
4663 custom_vsync();
4664
4665 int32_t step = 16;
4666
4667 if(*scale2 < 1.0)
4668 step = int32_t(4.0/ *scale2);
4669
4670 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
4671 step <<= 2;
4672
4673 if(CHECK_CTRL_CMD)
4674 step >>= 1;
4675
4676 if(key[KEY_UP])
4677 {
4678 *py2+=step;
4679 redraw=true;
4680 }
4681
4682 if(key[KEY_DOWN])
4683 {
4684 *py2-=step;
4685 redraw=true;
4686 }
4687
4688 if(key[KEY_LEFT])
4689 {
4690 *px2+=step;
4691 redraw=true;
4692 }
4693
4694 if(key[KEY_RIGHT])
4695 {
4696 *px2-=step;
4697 redraw=true;
4698 }
4699
4700 if(keypressed() && !redraw)
4701 switch(readkey()>>8)
4702 {
4703 case KEY_PGUP:
4704 *scale2*=0.95;
4705
4706 if(*scale2<0.1) *scale2=0.1;
4707
4708 redraw=true;
4709 break;
4710
4711 case KEY_PGDN:
4712 *scale2/=0.95;
4713
4714 if(*scale2>5.0) *scale2=5.0;
4715
4716 redraw=true;
4717 break;
4718
4719 case KEY_HOME:
4720 *scale2/=2.0;
4721
4722 if(*scale2<0.1) *scale2=0.1;
4723
4724 redraw=true;
4725 break;
4726
4727 case KEY_END:
4728 *scale2*=2.0;
4729
4730 if(*scale2>5.0) *scale2=5.0;
4731
4732 redraw=true;
4733 break;
4734
4735 case KEY_TILDE:
4736 *scale2=0.5;
4737 redraw=true;
4738 break;
4739
4740 case KEY_Z:
4741 *px2=w-zq_screen_w;
4742 *py2=h-zq_screen_h;
4743 vp_center=false;
4744 redraw=true;
4745 break;
4746
4747 case KEY_1:
4748 *scale2=1.0;
4749 redraw=true;
4750 break;
4751
4752 case KEY_2:
4753 *scale2=2.0;
4754 redraw=true;
4755 break;
4756
4757 case KEY_3:
4758 *scale2=3.0;
4759 redraw=true;
4760 break;
4761
4762 case KEY_4:
4763 *scale2=4.0;
4764 redraw=true;
4765 break;
4766
4767 case KEY_5:
4768 *scale2=5.0;
4769 redraw=true;
4770 break;
4771
4772 case KEY_C:
4773 *px2=*py2=0;
4774 redraw=vp_center=true;
4775 break;
4776
4777 case KEY_S:
4778 vp_showsize = !vp_showsize;
4779 redraw=true;
4780 break;
4781
4782 case KEY_D:
4783 vp_showpal = !vp_showpal;
4784 redraw=true;
4785 break;
4786
4787 case KEY_P:
4788 if(isviewingmap) break;
4789
4790 case KEY_ESC:
4791 done=true;
4792 break;
4793
4794 case KEY_SPACE:
4795 close_the_map();
4796 // TODO: why is `load_the_map` rendering a black dialog?
4797 if(isviewingmap ? load_the_map(skipmenu) : load_the_pic(pictoview,pal)==2)
4798 {
4799 done=true;
4800 }
4801 else
4802 {
4803 redraw=true;
4804 gui_bg_color = pblack;
4805 gui_fg_color = pwhite;
4806 *scale2=1.0;
4807 zc_set_palette(pal);
4808 }
4809
4810 get_bw(pal,pblack,pwhite);
4811 break;
4812 }
4813 }
4814 while(!done);
4815
4816 destroy_bitmap(buf);
4817 zc_set_palette(RAMpal);
4818 gui_fg_color = oldfgcolor;
4819 gui_bg_color = oldbgcolor;
4820
4821 popup_zqdialog_end();
4822 position_mouse_z(0);
4823 viewer_overlay_rti.remove();
4824 close_the_map();
4825 return D_O_K;
4826 }
4827
4828 static DIALOG loadmap_dlg[] =
4829 {
4830 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
4831 { jwin_win_proc, 0, 0, 225, 143, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Map", NULL, NULL },
4832 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
4833 { jwin_text_proc, 32, 26, 96, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Resolution", NULL, NULL },
4834 // 3
4835 { jwin_radio_proc, 16, 36, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/4 - 1024x352", NULL, NULL },
4836 { jwin_radio_proc, 16, 46, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "1/2 - 2048x704", NULL, NULL },
4837 { jwin_radio_proc, 16, 56, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full - 4096x1408", NULL, NULL },
4838 { jwin_text_proc, 144, 26, 97, 9, vc(11), vc(1), 0, 0, 0, 0, (void *) "Options", NULL, NULL },
4839 // 7
4840 { jwin_check_proc, 144, 36, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Solidity", NULL, NULL },
4841 { jwin_check_proc, 144, 46, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Flags", NULL, NULL },
4842 { jwin_check_proc, 144, 56, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Dark", NULL, NULL },
4843 { jwin_check_proc, 144, 66, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Items", NULL, NULL },
4844 // 11
4845 { jwin_button_proc, 42, 110, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
4846 { jwin_button_proc, 122, 110, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
4847 { jwin_check_proc, 16, 88, 97, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Save to Image", NULL, NULL },
4848 // 14
4849 { jwin_radio_proc, 16, 66, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"2x - 8192x2816", NULL, NULL },
4850 { jwin_radio_proc, 16, 76, 97, 9, vc(14), vc(1), 0, 0, 0, 0, (void*)"4x - 16384x5632", NULL, NULL },
4851 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
4852 };
4853
4854 int32_t load_the_map(bool skipmenu)
4855 {
4856 static int32_t res = 0;
4857 static int32_t flags = cDEBUG;
4858
4859 loadmap_dlg[0].dp2 = get_zc_font(font_lfont);
4860 loadmap_dlg[3].flags = (res==2) ? D_SELECTED : 0;
4861 loadmap_dlg[4].flags = (res==1) ? D_SELECTED : 0;
4862 loadmap_dlg[5].flags = (res==0) ? D_SELECTED : 0;
4863 loadmap_dlg[7].flags = (flags&cWALK) ? D_SELECTED : 0;
4864 loadmap_dlg[8].flags = (flags&cFLAGS) ? D_SELECTED : 0;
4865 loadmap_dlg[9].flags = (flags&cNODARK) ? 0 : D_SELECTED;
4866 loadmap_dlg[10].flags = (flags&cNOITEM) ? 0 : D_SELECTED;
4867 loadmap_dlg[13].flags = 0;
4868 loadmap_dlg[14].flags = (res==3) ? D_SELECTED : 0;
4869 loadmap_dlg[15].flags = (res==4) ? D_SELECTED : 0;
4870
4871 if(!skipmenu)
4872 {
4873 large_dialog(loadmap_dlg);
4874
4875 if (do_zqdialog(loadmap_dlg, 11) != 11)
4876 {
4877 return 1;
4878 }
4879
4880 flags = cDEBUG;
4881
4882 if(loadmap_dlg[3].flags&D_SELECTED) res=2;
4883
4884 if(loadmap_dlg[4].flags&D_SELECTED) res=1;
4885
4886 if(loadmap_dlg[5].flags&D_SELECTED) res=0;
4887
4888 if(loadmap_dlg[7].flags&D_SELECTED) flags|=cWALK;
4889
4890 if(loadmap_dlg[8].flags&D_SELECTED) flags|=cFLAGS;
4891
4892 if(!(loadmap_dlg[9].flags&D_SELECTED)) flags|=cNODARK;
4893
4894 if(!(loadmap_dlg[10].flags&D_SELECTED)) flags|=cNOITEM;
4895
4896 if(loadmap_dlg[14].flags&D_SELECTED) res=3;
4897
4898 if(loadmap_dlg[15].flags&D_SELECTED) res=4;
4899 }
4900
4901 int32_t bw = (256*16)>>res;
4902 int32_t bh = (176*8)>>res;
4903 int32_t sw = 256>>res;
4904 int32_t sh = 176>>res;
4905 if(res>2)
4906 {
4907 bw = (256*16)<<(res-2);
4908 bh = (176*8)<<(res-2);
4909 sw = 256<<(res-2);
4910 sh = 176<<(res-2);
4911 }
4912
4913 rti_map_view.flags = flags;
4914 rti_map_view.bw = bw;
4915 rti_map_view.bh = bh;
4916 rti_map_view.sw = sw;
4917 rti_map_view.sh = sh;
4918 rti_map_view.set_size(bw, bh);
4919 rti_map_view.dirty = true;
4920 get_root_rti()->add_child(&rti_map_view);
4921 render_zq();
4922
4923 vp_showpal = false;
4924 get_bw(picpal,pblack,pwhite);
4925 mapx = mapy = 0;
4926 mapscale = 1;
4927 imagepath[0] = 0;
4928
4929 if(loadmap_dlg[13].flags & D_SELECTED) saveMapAsImage(rti_map_view.bitmap);
4930
4931 memcpy(mappal,RAMpal,sizeof(RAMpal));
4932
4933 return 0;
4934 }
4935
4936 void close_the_map()
4937 {
4938 rti_map_view.remove();
4939 }
4940
4941 int32_t onViewMap()
4942 {
4943 return onViewMapEx(false);
4944 }
4945 int32_t onViewMapEx(bool skipmenu)
4946 {
4947 int32_t temp_aligns=ShowMisalignments;
4948 ShowMisalignments=0;
4949 //if(load_the_map()==0)
4950 //{
4951 launchPicViewer(&bmap,mappal,&mapx, &mapy, &mapscale,true,skipmenu);
4952 //}
4953 ShowMisalignments=temp_aligns;
4954 return D_O_K;
4955 }
4956
4957 static const char *mazedirstr[4] = {"North","South","West","East"};
4958 char _pathstr[40]="North,North,North,North";
4959
4960 char *pathstr(byte path[])
4961 {
4962 sprintf(_pathstr,"%s,%s,%s,%s",mazedirstr[path[0]],mazedirstr[path[1]],
4963 mazedirstr[path[2]],mazedirstr[path[3]]);
4964 return _pathstr;
4965 }
4966
4967 char _ticksstr[32]="99.99 seconds";
4968
4969 char *ticksstr(int32_t tics)
4970 {
4971 int32_t mins=tics/(60*60);
4972 tics=tics-(mins*60*60);
4973 int32_t secs=tics/60;
4974 tics=tics-(secs*60);
4975 tics=tics*100/60;
4976
4977 if(mins>0)
4978 {
4979 sprintf(_ticksstr,"%d:%02d.%02d",mins, secs, tics);
4980 }
4981 else
4982 {
4983 sprintf(_ticksstr,"%d.%02d seconds",secs, tics);
4984 }
4985
4986 return _ticksstr;
4987 }
4988 void textprintf_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
4989 {
4990 char buf[512];
4991 va_list ap;
4992 ASSERT(bmp);
4993 ASSERT(f);
4994 ASSERT(format);
4995
4996 va_start(ap, format);
4997 uvszprintf(buf, sizeof(buf), format, ap);
4998 va_end(ap);
4999
5000
5001 textout_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
5002
5003 textout_ex(bmp, f, buf, x, y, color_sh, -1);
5004 }
5005
5006 void textprintf_centre_disabled(BITMAP *bmp, AL_CONST FONT *f, int32_t x, int32_t y, int32_t color_hl, int32_t color_sh, AL_CONST char *format, ...)
5007 {
5008 char buf[512];
5009 va_list ap;
5010 ASSERT(bmp);
5011 ASSERT(f);
5012 ASSERT(format);
5013
5014 va_start(ap, format);
5015 uvszprintf(buf, sizeof(buf), format, ap);
5016 va_end(ap);
5017
5018 textout_centre_ex(bmp, f, buf, x+1, y+1, color_hl, -1);
5019 textout_centre_ex(bmp, f, buf, x, y, color_sh, -1);
5020 }
5021
5022 void draw_sqr_frame(size_and_pos const& sqr)
5023 {
5024 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.tw(),sqr.th(),FR_DEEP);
5025 }
5026 void draw_sqr_icon(size_and_pos const& sqr, BITMAP* icon)
5027 {
5028 stretch_blit(icon, menu1, 0, 0, 16, 16, sqr.x+2, sqr.y+2, sqr.tw()-4, sqr.th()-4);
5029 }
5030 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num)
5031 {
5032 if(center)
5033 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5034 else
5035 textprintf_ex(menu1,f,sqr.x+txtoffs_single.x,sqr.y+txtoffs_single.y,jwin_pal[jcBOXFG],-1,"%d",num);
5036 }
5037 void draw_sqr_nums(size_and_pos const& sqr, FONT* f, bool center, int num1, int num2)
5038 {
5039 if(center)
5040 {
5041 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5042 textprintf_centre_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5043 }
5044 else
5045 {
5046 textprintf_ex(menu1,f,sqr.x+txtoffs_double_1.x,sqr.y+txtoffs_double_1.y,jwin_pal[jcBOXFG],-1,"%d",num1);
5047 textprintf_ex(menu1,f,sqr.x+txtoffs_double_2.x,sqr.y+txtoffs_double_2.y,jwin_pal[jcBOXFG],-1,"%d",num2);
5048 }
5049 }
5050 void draw_sqr_btn(size_and_pos const& sqr, const char* txt, int flags, FONT* f = nullptr)
5051 {
5052 if(sqr.x < 0) return;
5053 FONT* tfont = font;
5054 if(f)
5055 font = f;
5056 draw_text_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), txt, 0, 0, flags, true);
5057 font = tfont;
5058 }
5059 void draw_sqr_btn(size_and_pos const& sqr, int icon, int flags, FONT* f = nullptr)
5060 {
5061 if(sqr.x < 0) return;
5062 FONT* tfont = font;
5063 if(f)
5064 font = f;
5065 draw_icon_button(menu1, sqr.x, sqr.y, sqr.tw(), sqr.th(), icon, 0, 0, flags, true);
5066 font = tfont;
5067 }
5068
5069 void drawpanel()
5070 {
5071 mapscr *scr=Map.CurrScr();
5072 int32_t NextCombo = combobuf[Combo].nextcombo;
5073 int32_t NextCSet = combobuf[Combo].nextcset;
5074 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
5075 {
5076 NextCombo = scr->undercombo;
5077 NextCSet = scr->undercset;
5078 }
5079 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
5080 NextCSet = CSet;
5081
5082 FONT* tfont = font;
5083 if(prv_mode)
5084 {
5085 jwin_draw_frame(menu1,0,preview_panel.y,preview_panel.x+preview_panel.w, preview_panel.h, FR_WIN);
5086 rectfill(menu1,preview_panel.x,preview_panel.y+2,preview_panel.x+preview_panel.w-3,preview_panel.y+preview_panel.h-3,jwin_pal[jcBOX]);
5087 }
5088 else
5089 {
5090 auto& sqr = main_panel;
5091 rectfill(menu1,sqr.x,sqr.y,sqr.x+sqr.w-1,sqr.y+sqr.h-1, jwin_pal[jcBOX]);
5092 refresh(rSCRMAP);
5093 jwin_draw_frame(menu1,sqr.x,sqr.y,sqr.w,sqr.h, FR_WIN);
5094
5095 font = get_custom_font(CFONT_GUI);
5096 draw_sqr_btn(squarepanel_swap_btn, "SWP", 0);
5097 if(compact_square_panels)
5098 {
5099 textprintf_centre_ex(menu1,font,squarepanel_up_btn.cx(),squarepanel_up_btn.y-text_height(font)-2,jwin_pal[jcBOXFG],-1,"%d",compact_active_panel);
5100 draw_sqr_btn(squarepanel_up_btn, BTNICON_ARROW_UP, 0);
5101 draw_sqr_btn(squarepanel_down_btn, BTNICON_ARROW_DOWN, 0);
5102 }
5103 font = tfont;
5104
5105 FONT* sqr_text_font = (is_compact && compact_square_panels) ? get_custom_font(CFONT_GUI) : font;
5106 //Item:
5107 if(itemsqr_pos.x > -1)
5108 {
5109 draw_sqr_frame(itemsqr_pos);
5110 if(scr->hasitem)
5111 {
5112 rectfill(menu1,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsqr_pos.x+itemsqr_pos.tw()-3,itemsqr_pos.y+itemsqr_pos.th()-3,0);
5113 overtile16_scale(menu1, itemsbuf[scr->item].tile,itemsqr_pos.x+2,itemsqr_pos.y+2,itemsbuf[scr->item].csets&15,0,itemsqr_pos.tw()-4,itemsqr_pos.th()-4);
5114 }
5115 else draw_sqr_icon(itemsqr_pos, icon_bmp[0][coord_frame]);
5116 draw_sqr_nums(itemsqr_pos, sqr_text_font, panel_align == 1, scr->itemx, scr->itemy);
5117 }
5118 //Flag:
5119 if(flagsqr_pos.x > -1)
5120 {
5121 draw_sqr_frame(flagsqr_pos);
5122 draw_sqr_icon(flagsqr_pos,flag_bmp[Flag%16][coord_frame]);
5123 draw_sqr_nums(flagsqr_pos, sqr_text_font, panel_align == 1, Flag);
5124 }
5125
5126 //Stairs:
5127 if(stairsqr_pos.x > -1)
5128 {
5129 draw_sqr_frame(stairsqr_pos);
5130 draw_sqr_icon(stairsqr_pos,icon_bmp[1][coord_frame]);
5131 draw_sqr_nums(stairsqr_pos, sqr_text_font, panel_align == 1, scr->stairx, scr->stairy);
5132 }
5133
5134 //Green arrival square:
5135 bool disabled_arrival = get_qr(qr_NOARRIVALPOINT);
5136 if(warparrival_pos.x > -1)
5137 {
5138 draw_sqr_frame(warparrival_pos);
5139 BITMAP* icon = icon_bmp[2][coord_frame];
5140 if(disabled_arrival)
5141 {
5142 icon = create_bitmap_ex(8,16,16);
5143 blit(icon_bmp[2][0], icon, 0, 0, 0, 0, 16, 16);
5144 replColor(icon, 0xE7, 0xEA, 0xEA, false);
5145 replColor(icon, 0xE8, 0xE2, 0xE2, false);
5146 }
5147
5148 draw_sqr_icon(warparrival_pos, icon);
5149 draw_sqr_nums(warparrival_pos, sqr_text_font, panel_align == 1, scr->warparrivalx, scr->warparrivaly);
5150
5151 if(disabled_arrival)
5152 destroy_bitmap(icon);
5153 }
5154
5155 //Blue return squares:
5156 for(int32_t i=0; i<4; i++)
5157 {
5158 if(warpret_pos[i].x < 0) continue;
5159 draw_sqr_frame(warpret_pos[i]);
5160 draw_sqr_icon(warpret_pos[i], icon_bmp[ICON_BMP_RETURN_A+i][coord_frame]);
5161 draw_sqr_nums(warpret_pos[i], sqr_text_font, panel_align == 1, scr->warpreturnx[i], scr->warpreturny[i]);
5162 }
5163
5164 // Enemies
5165 auto& ep = enemy_prev_pos;
5166 if(ep.x > -1)
5167 {
5168 if(ep.fw > -1)
5169 {
5170 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5171 rectfill(menu1, ep.x+ep.fw, ep.y+ep.fh, ep.x+ep.tw()-1, ep.y+ep.th()-1, jwin_pal[jcBOX]);
5172 jwin_draw_frag_frame(menu1, ep.x, ep.y, ep.tw(), ep.th(), ep.fw, ep.fh, FR_DEEP);
5173 }
5174 else
5175 {
5176 rectfill(menu1, ep.x, ep.y, ep.x+ep.tw()-1,ep.y+ep.th()-1,vc(0));
5177 draw_sqr_frame(ep);
5178 }
5179 for(int32_t i=0; i< 10 && Map.CurrScr()->enemy[i]!=0; i++)
5180 {
5181 int32_t id = Map.CurrScr()->enemy[i];
5182 int32_t tile = get_qr(qr_NEWENEMYTILES) ? guysbuf[id].e_tile : guysbuf[id].tile;
5183 int32_t cset = guysbuf[id].cset;
5184 auto& sqr = ep.subsquare(i);
5185 if(tile)
5186 overtile16_scale(menu1, tile+efrontfacingtile(id),sqr.x,sqr.y,cset,0,sqr.tw(),sqr.th());
5187 }
5188 }
5189 }
5190 font = tfont;
5191 }
5192
5193 void show_screen_error(const char *str, int32_t i, int32_t c)
5194 {
5195 rectfill(menu1, screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),screrrorpos.x,screrrorpos.y-((i-1)*16)-4,vc(0));
5196 textout_shadowed_ex(menu1,get_zc_font(font_lfont_l), str,screrrorpos.x-text_length(get_zc_font(font_lfont_l),str),screrrorpos.y-(i*16),c,vc(0),-1);
5197 }
5198
5199 void tile_warp_notification(int32_t which, char *buf)
5200 {
5201 char letter = 'A'+which;
5202
5203 switch(Map.CurrScr()->tilewarptype[which])
5204 {
5205 case wtCAVE:
5206 sprintf(buf,"Tile Warp %c: Cave/Item Cellar",letter);
5207 break;
5208
5209 default:
5210 {
5211 char buf2[30];
5212
5213 if(strlen(DMaps[Map.CurrScr()->tilewarpdmap[which]].name)==0)
5214 {
5215 sprintf(buf2,"%d",Map.CurrScr()->tilewarpdmap[which]);
5216 }
5217 else
5218 sprintf(buf2,"%d-%s",Map.CurrScr()->tilewarpdmap[which],DMaps[Map.CurrScr()->tilewarpdmap[which]].name);
5219
5220 sprintf(buf,"Tile Warp %c: %s, %02X", letter, buf2, Map.CurrScr()->tilewarpscr[which]);
5221 break;
5222 }
5223
5224 case wtNOWARP:
5225 sprintf(buf,"Tile Warp %c: Cancel Warp", letter);
5226 break;
5227 }
5228 }
5229
5230 void side_warp_notification(int32_t which, int32_t dir, char *buf)
5231 {
5232 char letter = 'A'+which;
5233 char buf3[16];
5234
5235 if(dir==0 && Map.CurrScr()->timedwarptics)
5236 sprintf(buf3,"%s, Timed",mazedirstr[dir]);
5237 else if(dir==4)
5238 sprintf(buf3,"Timed");
5239 else
5240 strcpy(buf3, mazedirstr[dir]);
5241
5242 switch(Map.CurrScr()->sidewarptype[which])
5243 {
5244 case wtCAVE:
5245 sprintf(buf,"Side Warp %c (%s): Cave/Item Cellar",letter, buf3);
5246 break;
5247
5248 default:
5249 {
5250 // Destination DMap name
5251 if(strlen(DMaps[Map.CurrScr()->sidewarpdmap[which]].name)==0)
5252 {
5253 sprintf(buf,"Side Warp %c (%s): %d, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which], Map.CurrScr()->sidewarpscr[which]);
5254 }
5255 else
5256 sprintf(buf,"Side Warp %c (%s): %d-%s, %02X", letter, buf3, Map.CurrScr()->sidewarpdmap[which],DMaps[Map.CurrScr()->sidewarpdmap[which]].name, Map.CurrScr()->sidewarpscr[which]);
5257
5258 break;
5259 }
5260
5261 case wtNOWARP:
5262 sprintf(buf,"Side Warp %c (%s): Cancel Warp", letter, buf3);
5263 break;
5264 }
5265 }
5266
5267 static bool arrowcursor = true; // Used by combo aliases and Combo Brush cursors. -L
5268
5269 void xout(BITMAP* dest, int x, int y, int x2, int y2, int c, int bgc = -1)
5270 {
5271 //BG Fill
5272 if(bgc > -1)
5273 rectfill(dest, x, y, x2, y2, bgc);
5274 ++x; ++y; --x2; --y2;
5275 //Border
5276 safe_rect(dest, x, y, x2, y2, c);
5277 //line(dest, x, y, x2, y, c);
5278 //line(dest, x, y, x, y2, c);
5279 //X
5280 line(dest, x, y, x2, y2, c);
5281 line(dest, x, y2, x2, y, c);
5282 }
5283
5284 void put_autocombo_engravings(BITMAP* dest, combo_auto const& ca, bool selected, int32_t x, int32_t y, int32_t scale)
5285 {
5286 if (!ca.valid())
5287 {
5288 if (ca.getDisplay() > 0)
5289 put_engraving(dest, x, y, 15, scale);
5290 }
5291 else
5292 {
5293 if (ca.getType() == AUTOCOMBO_Z4 || ca.getType() == AUTOCOMBO_DOR)
5294 {
5295 byte hei = vbound(ca.getArg() + 1, 1, 9);
5296 if (selected)
5297 hei = vbound(cauto_height, 1, 9);
5298 put_engraving(dest, x, y, 15 - hei, scale);
5299 }
5300 }
5301 }
5302
5303 void draw_screenunit_map_screen(VisibleScreen visible_screen)
5304 {
5305 int num_screens_to_draw = Map.getViewSize();
5306 int screen = visible_screen.screen;
5307 int xoff = visible_screen.xoff;
5308 int yoff = visible_screen.yoff;
5309
5310 mapscr* scr = visible_screen.scr;
5311 if (!layers_valid(scr))
5312 fix_layers(scr, true);
5313
5314 clear_to_color(mapscreenbmp, jwin_pal[jcBOX]);
5315 if (LayerDitherBG > -1)
5316 {
5317 if (LayerDitherSz > 0)
5318 ditherblit(mapscreenbmp, nullptr, vc(LayerDitherBG), dithChecker, LayerDitherSz);
5319 else
5320 clear_to_color(mapscreenbmp, vc(LayerDitherBG));
5321 }
5322
5323 int view_scr_x = Map.getViewScr() % 16;
5324 int view_scr_y = Map.getViewScr() / 16;
5325 int scr_x = screen % 16;
5326 int scr_y = screen / 16;
5327 int edge_xoff = 0, edge_yoff = 0;
5328 if(showedges)
5329 {
5330 if (scr_x == view_scr_x)
5331 edge_xoff = 16;
5332 else
5333 xoff -= 16;
5334
5335 if (scr_y == view_scr_y)
5336 edge_yoff = 16;
5337 else
5338 yoff -= 16;
5339 }
5340
5341 combotile_add_x = mapscreen_x + xoff;
5342 combotile_add_y = mapscreen_y + yoff;
5343 combotile_mul_x = mapscreen_single_scale;
5344 combotile_mul_y = mapscreen_single_scale;
5345 Map.draw(mapscreenbmp, scr_x == view_scr_x && showedges ? 16 : 0, scr_y == view_scr_y && showedges ? 16 : 0, Flags, Map.getCurrMap(), screen, ActiveLayerHighlight ? CurrentLayer : -1);
5346 combotile_add_x = 0;
5347 combotile_add_y = 0;
5348 combotile_mul_x = 1;
5349 combotile_mul_y = 1;
5350
5351 // TODO: should be better to move this out of draw_screenunit_map_screen.
5352 if (showedges && screen < 128)
5353 {
5354 bool peek_above = scr_y == view_scr_y;
5355 bool peek_below = scr_y == view_scr_y + num_screens_to_draw - 1;
5356 bool peek_left = scr_x == view_scr_x;
5357 bool peek_right = scr_x == view_scr_x + num_screens_to_draw - 1;
5358
5359 int right_col = 272 - (num_screens_to_draw > 1 ? 16 : 0);
5360 int bottom_row = 192 - (num_screens_to_draw > 1 ? 16 : 0);
5361
5362 //not the first row of screens
5363 if (peek_above)
5364 {
5365 if(screen>15 && !NoScreenPreview)
5366 {
5367 Map.drawrow(mapscreenbmp, edge_xoff, 0, Flags, 160, -1, screen-16);
5368 }
5369 else
5370 {
5371 Map.drawstaticrow(mapscreenbmp, edge_xoff, 0);
5372 }
5373 }
5374
5375 //not the last row of screens
5376 if (peek_below)
5377 {
5378 if(screen + 16 < 0x80 && !NoScreenPreview)
5379 {
5380 Map.drawrow(mapscreenbmp, edge_xoff, bottom_row, Flags, 0, -1, screen+16);
5381 }
5382 else
5383 {
5384 Map.drawstaticrow(mapscreenbmp, edge_xoff, bottom_row);
5385 }
5386 }
5387
5388 //not the first column of screens
5389 if (peek_left)
5390 {
5391 if(screen&0x0F && !NoScreenPreview)
5392 {
5393 Map.drawcolumn(mapscreenbmp, 0, edge_yoff, Flags, 15, -1, screen-1);
5394 }
5395 else
5396 {
5397 Map.drawstaticcolumn(mapscreenbmp, 0, edge_yoff);
5398 }
5399 }
5400
5401 //not the last column of screens
5402 if (peek_right)
5403 {
5404 if((screen&0x0F)<15 && !NoScreenPreview)
5405 {
5406 Map.drawcolumn(mapscreenbmp, right_col, edge_yoff, Flags, 0, -1, screen+1);
5407 }
5408 else
5409 {
5410 Map.drawstaticcolumn(mapscreenbmp, right_col, edge_yoff);
5411 }
5412 }
5413
5414 //not the first row or first column of screens
5415 if (peek_above && peek_left)
5416 {
5417 if((screen>15)&&(screen&0x0F) && !NoScreenPreview)
5418 {
5419 Map.drawblock(mapscreenbmp, 0, 0, Flags, 175, -1, screen-17);
5420 }
5421 else
5422 {
5423 Map.drawstaticblock(mapscreenbmp, 0, 0);
5424 }
5425 }
5426
5427 //not the first row or last column of screens
5428 if (peek_above && peek_right)
5429 {
5430 if((screen>15)&&((screen&0x0F)<15) && !NoScreenPreview)
5431 {
5432 Map.drawblock(mapscreenbmp, right_col, 0, Flags, 160, -1, screen-15);
5433 }
5434 else
5435 {
5436 Map.drawstaticblock(mapscreenbmp, right_col, 0);
5437 }
5438 }
5439
5440 //not the last row or first column of screens
5441 if (peek_below && peek_left)
5442 {
5443 if((screen<112)&&(screen&0x0F) && !NoScreenPreview)
5444 {
5445 Map.drawblock(mapscreenbmp, 0, bottom_row, Flags, 15, -1, screen+15);
5446 }
5447 else
5448 {
5449 Map.drawstaticblock(mapscreenbmp, 0, bottom_row);
5450 }
5451 }
5452
5453 //not the last row or last column of screens
5454 if (peek_below && peek_right)
5455 {
5456 if((screen<112)&&((screen&0x0F)<15) && !NoScreenPreview)
5457 {
5458 Map.drawblock(mapscreenbmp, right_col, bottom_row, Flags, 0, -1, screen+17);
5459 }
5460 else
5461 {
5462 Map.drawstaticblock(mapscreenbmp, right_col, bottom_row);
5463 }
5464 }
5465 }
5466
5467 if (ShowSquares && Map.getViewSize() < 4)
5468 {
5469 if(scr->stairx || scr->stairy)
5470 {
5471 int32_t x1 = scr->stairx+edge_xoff;
5472 int32_t y1 = scr->stairy+edge_yoff;
5473 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(14));
5474 }
5475
5476 if(scr->warparrivalx || scr->warparrivaly)
5477 {
5478 int32_t x1 = scr->warparrivalx +edge_xoff;
5479 int32_t y1 = scr->warparrivaly +edge_yoff;
5480 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,vc(10));
5481 }
5482
5483 for(int32_t i=0; i<4; i++) if(scr->warpreturnx[i] || scr->warpreturny[i])
5484 {
5485 int32_t x1 = scr->warpreturnx[i]+edge_xoff;
5486 int32_t y1 = scr->warpreturny[i]+edge_yoff;
5487 int32_t clr = vc(9);
5488
5489 if(FlashWarpSquare==i)
5490 {
5491 if(!FlashWarpClk)
5492 FlashWarpSquare=-1;
5493 else if(!(--FlashWarpClk%3))
5494 clr = vc(15);
5495 }
5496
5497 safe_rect(mapscreenbmp,x1,y1,x1+15,y1+15,clr);
5498 }
5499 }
5500
5501 if(ShowFFCs)
5502 {
5503 mapscr* ffscr = prv_mode ? Map.get_prvscr() : scr;
5504 int num_ffcs = ffscr->numFFC();
5505 for(int32_t i=num_ffcs-1; i>=0; i--)
5506 {
5507 ffcdata& ff = ffscr->ffcs[i];
5508 if(ff.data !=0 && (CurrentLayer<2 || (ff.flags&ffc_overlay)))
5509 {
5510 auto x = ff.x+edge_xoff;
5511 auto y = ff.y+edge_yoff;
5512 safe_rect(mapscreenbmp, x+0, y+0, x+ff.txsz*16-1, y+ff.tysz*16-1, vc(12));
5513 }
5514 }
5515 }
5516
5517 if(!(Flags&cDEBUG) && pixeldb==1)
5518 {
5519 for(int32_t j=168; j<176; j++)
5520 {
5521 for(int32_t i=0; i<256; i++)
5522 {
5523 if(((i^j)&1)==0)
5524 {
5525 putpixel(mapscreenbmp,edge_xoff+i,
5526 edge_yoff+j,vc(blackout_color));
5527 }
5528 }
5529 }
5530 }
5531
5532 int w = mapscreenbmp->w * mapscreen_single_scale;
5533 int h = mapscreenbmp->h * mapscreen_single_scale;
5534 stretch_blit(mapscreenbmp, menu1, 0, 0, mapscreenbmp->w, mapscreenbmp->h, mapscreen_x + xoff, mapscreen_y + yoff, w, h);
5535 }
5536
5537 void draw_screenunit(int32_t unit, int32_t flags)
5538 {
5539 FONT* tfont = font;
5540 switch(unit)
5541 {
5542 case rSCRMAP:
5543 {
5544 size_and_pos *mini_sqr = &minimap;
5545 size_and_pos *real_mini_sqr = &real_minimap;
5546
5547 if(zoomed_minimap)
5548 {
5549 mini_sqr = &minimap_zoomed;
5550 real_mini_sqr = &real_minimap_zoomed;
5551 }
5552
5553 auto txt_x = real_mini_sqr->x+2+8*real_mini_sqr->xscale;
5554 auto txt_y = real_mini_sqr->y+2+8*real_mini_sqr->yscale;
5555
5556 rectfill(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->x+mini_sqr->w-1,mini_sqr->y+mini_sqr->h-1,jwin_pal[jcBOX]);
5557 if(zoomed_minimap)
5558 jwin_draw_frame(menu1, mini_sqr->x-1, mini_sqr->y-2,mini_sqr->w,mini_sqr->h,FR_WIN);
5559 jwin_draw_minimap_frame(menu1,real_mini_sqr->x,real_mini_sqr->y,real_mini_sqr->tw(), real_mini_sqr->th(), real_mini_sqr->xscale, FR_DEEP);
5560
5561 if(Map.getCurrMap()<Map.getMapCount())
5562 {
5563 for(int32_t i=0; i<MAPSCRS; i++)
5564 {
5565 auto& sqr = real_mini_sqr->subsquare(i);
5566
5567 if(Map.Scr(i)->valid&mVALID)
5568 {
5569 // Handled by mmap_draw.
5570 }
5571 else
5572 {
5573 if (InvalidBG == 2)
5574 {
5575 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
5576 }
5577 else if (InvalidBG == 1)
5578 {
5579 for(int32_t dy=0; dy<sqr.h; dy++)
5580 {
5581 for(int32_t dx=0; dx<sqr.w; dx++)
5582 {
5583 menu1->line[dy+sqr.y][dx+sqr.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
5584 }
5585 }
5586 }
5587 else
5588 {
5589 int32_t offs = 2*(sqr.w/9);
5590 draw_x(menu1, sqr.x+offs, sqr.y+offs, sqr.x+sqr.w-1-offs, sqr.y+sqr.h-1-offs, vc(15));
5591 }
5592 }
5593 }
5594
5595 int32_t s=Map.getCurrScr();
5596
5597 BITMAP* txtbmp = create_bitmap_ex(8,256,64);
5598 clear_bitmap(txtbmp);
5599 int txtscale = zoomed_minimap ? (is_compact ? 2 : 3) : 1;
5600 font = get_zc_font(font_lfont_l);
5601
5602 int32_t space = text_length(font, "255")+2, spc_s = text_length(font, "S")+2, spc_m = text_length(font, "M")+2;
5603 textprintf_disabled(txtbmp,font,0,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"M");
5604 static int map_shortcut_tooltip_id = ttip_register_id();
5605 ttip_install(map_shortcut_tooltip_id, "Prev map: ,\nNext map: .", txt_x, txt_y, 30, 20, txt_x, txt_y - 60);
5606
5607 textprintf_ex(txtbmp,font,spc_m,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%-3d",Map.getCurrMap()+1);
5608
5609 textprintf_disabled(txtbmp,font,spc_m+space,0,jwin_pal[jcLIGHT],jwin_pal[jcMEDDARK],"S");
5610 textprintf_ex(txtbmp,font,spc_m+space+spc_s,0,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"0x%02X (%d)",s, s);
5611 masked_stretch_blit(txtbmp, menu1, 0, 0, 256, 64, txt_x, txt_y, 256*txtscale, 64*txtscale);
5612 destroy_bitmap(txtbmp);
5613 }
5614 }
5615 break;
5616 case rMAP:
5617 {
5618 refresh_visible_screens();
5619 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
5620
5621 int num_combos_width = 16 * Map.getViewSize();
5622 int num_combos_height = 11 * Map.getViewSize();
5623
5624 if(CurrentLayer > 0 && !mapscreen_valid_layers[CurrentLayer-1])
5625 CurrentLayer = 0;
5626
5627 for (auto& vis_screen : visible_screens)
5628 {
5629 draw_screenunit_map_screen(vis_screen);
5630 }
5631
5632 if (showxypos_icon)
5633 {
5634 int x0 = showxypos_x + (showedges?16:0);
5635 int y0 = showxypos_y + (showedges?16:0);
5636 int x1 = x0 + showxypos_w - 1;
5637 int y1 = y0 + showxypos_h - 1;
5638 x0 *= mapscreen_single_scale;
5639 y0 *= mapscreen_single_scale;
5640 x1 *= mapscreen_single_scale;
5641 y1 *= mapscreen_single_scale;
5642 x0 += mapscreen_x;
5643 y0 += mapscreen_y;
5644 x1 += mapscreen_x;
5645 y1 += mapscreen_y;
5646
5647 if (showxypos_color == vc(15))
5648 safe_rect(menu1, x0, y0, x1, y1, showxypos_color);
5649 else
5650 rectfill(menu1, x0, y0, x1, y1, showxypos_color);
5651 }
5652
5653 if(showxypos_cursor_icon)
5654 {
5655 int x0 = showxypos_cursor_x + (showedges?16:0);
5656 int y0 = showxypos_cursor_y + (showedges?16:0);
5657 int x1 = x0 + showxypos_w - 1;
5658 int y1 = y0 + showxypos_h - 1;
5659 x0 *= mapscreen_single_scale;
5660 y0 *= mapscreen_single_scale;
5661 x1 *= mapscreen_single_scale;
5662 y1 *= mapscreen_single_scale;
5663 x0 += mapscreen_x;
5664 y0 += mapscreen_y;
5665 x1 += mapscreen_x;
5666 y1 += mapscreen_y;
5667 safe_rect(menu1, x0, y0, x1, y1, showxypos_cursor_color);
5668 }
5669
5670 // Draw dithering over the edge/preview combos.
5671 if(showedges)
5672 {
5673 int tile_size = 16 * mapscreen_single_scale;
5674 int tiles_across = (16 * Map.getViewSize()) + 2;
5675 int bottom_row_y = (Map.getViewSize()*11 + 1) * tile_size;
5676 int right_col_x = (Map.getViewSize()*16 + 1) * tile_size;
5677
5678 //top preview
5679 for(int32_t j=0; j<tile_size; j++)
5680 {
5681 for(int32_t i=0; i<tiles_across * tile_size; i++)
5682 {
5683 if(((i^j)&1)==0)
5684 {
5685 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5686 }
5687 }
5688 }
5689
5690 //bottom preview
5691 for(int32_t j = bottom_row_y; j < bottom_row_y + tile_size; j++)
5692 {
5693 for(int32_t i=0; i<tiles_across * tile_size; i++)
5694 {
5695 if(((i^j)&1)==0)
5696 {
5697 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5698 }
5699 }
5700 }
5701
5702 //left preview
5703 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5704 {
5705 for(int32_t i=0; i<16*mapscreen_single_scale; i++)
5706 {
5707 if(((i^j)&1)==0)
5708 {
5709 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5710 }
5711 }
5712 }
5713
5714 //right preview
5715 for(int32_t j=tile_size; j<int32_t(192*mapscreen_screenunit_scale); j++)
5716 {
5717 for(int32_t i = right_col_x; i < right_col_x + tile_size; i++)
5718 {
5719 if(((i^j)&1)==0)
5720 {
5721 putpixel(menu1,mapscreen_x+i,mapscreen_y+j,vc(0));
5722 }
5723 }
5724 }
5725 }
5726
5727 if(!(Flags&cDEBUG) && pixeldb==2)
5728 {
5729 for(int32_t j=int32_t(168*mapscreen_single_scale); j<int32_t(176*mapscreen_single_scale); j++)
5730 {
5731 for(int32_t i=0; i<int32_t(256*mapscreen_single_scale); i++)
5732 {
5733
5734 if(((i^j)&1)==0)
5735 {
5736 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0)+i),
5737 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5738 }
5739 }
5740 }
5741 }
5742
5743 // TODO: This should move to `zmap::draw` (and delete the current code there doing a similar thing).
5744 if (Map.isDark(Map.getCurrScr()) && Map.getViewSize() == 1)
5745 {
5746 if((Flags&cNEWDARK) && get_qr(qr_NEW_DARKROOM))
5747 {
5748 BITMAP* tmpDark = create_bitmap_ex(8,16*16,16*11);
5749 BITMAP* tmpDarkTrans = create_bitmap_ex(8,16*16,16*11);
5750 BITMAP* tmpbuf = create_bitmap_ex(8,
5751 mapscreen_single_scale*(256+(showedges?32:0)),
5752 mapscreen_single_scale*(176+(showedges?32:0)));
5753 BITMAP* tmpbuf2 = create_bitmap_ex(8,
5754 mapscreen_single_scale*(256+(showedges?32:0)),
5755 mapscreen_single_scale*(176+(showedges?32:0)));
5756 int32_t darkCol = zinit.darkcol;
5757 switch(darkCol) //special cases
5758 {
5759 case BLACK:
5760 darkCol = vc(0);
5761 break;
5762 case WHITE:
5763 darkCol = vc(15);
5764 break;
5765 }
5766 clear_to_color(tmpDark, darkCol);
5767 clear_to_color(tmpDarkTrans, darkCol);
5768 clear_bitmap(tmpbuf);
5769 clear_bitmap(tmpbuf2);
5770 //Handle torch combos
5771 color_map = &trans_table2;
5772 Map.draw_darkness(tmpDark, tmpDarkTrans);
5773 //
5774 mapscr* tmp = Map.CurrScr();
5775 if(tmp->flags9 & fDARK_DITHER)
5776 {
5777 ditherblit(tmpDark, tmpDark, 0, zinit.dither_type, zinit.dither_arg);
5778 ditherblit(tmpDarkTrans, tmpDarkTrans, 0, zinit.dither_type, zinit.dither_arg);
5779 }
5780
5781 if(mapscreen_single_scale == 1)
5782 {
5783 blit(tmpDark, tmpbuf, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5784 blit(tmpDarkTrans, tmpbuf2, 0, 0, (showedges?16:0), (showedges?16:0), 16*16, 16*11);
5785 }
5786 else
5787 {
5788 stretch_blit(tmpDark, tmpbuf, 0, 0, 16*16, 16*11,
5789 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5790 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5791 stretch_blit(tmpDarkTrans, tmpbuf2, 0, 0, 16*16, 16*11,
5792 (showedges?16:0)*mapscreen_single_scale, (showedges?16:0)*mapscreen_single_scale,
5793 (16*16)*mapscreen_single_scale, (16*11)*mapscreen_single_scale);
5794 }
5795
5796 if(tmp->flags9 & fDARK_TRANS)
5797 {
5798 draw_trans_sprite(menu1, tmpbuf, mapscreen_x, mapscreen_y);
5799 }
5800 else
5801 {
5802 masked_blit(tmpbuf,menu1,0,0,mapscreen_x,mapscreen_y,tmpbuf->w,tmpbuf->h);
5803 }
5804 draw_trans_sprite(menu1, tmpbuf2, mapscreen_x, mapscreen_y);
5805 color_map = &trans_table;
5806 //
5807 destroy_bitmap(tmpDark);
5808 destroy_bitmap(tmpDarkTrans);
5809 destroy_bitmap(tmpbuf);
5810 destroy_bitmap(tmpbuf2);
5811 }
5812 else if(!(Flags&cNODARK))
5813 {
5814 for(int32_t j=0; j<80*mapscreen_single_scale; j++)
5815 {
5816 for(int32_t i=0; i<(80*mapscreen_single_scale)-j; i++)
5817 {
5818 if(((i^j)&1)==0)
5819 {
5820 putpixel(menu1,int32_t(mapscreen_x+(showedges?(16*mapscreen_single_scale):0))+i,
5821 int32_t(mapscreen_y+(showedges?(16*mapscreen_single_scale):0)+j),vc(blackout_color));
5822 }
5823 }
5824 }
5825 }
5826 }
5827
5828 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
5829 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
5830 bool inrect = isinRect(gui_mouse_x(),gui_mouse_y(),startx,starty,(startx+(256*mapscreen_screenunit_scale)-1),(starty+(176*mapscreen_screenunit_scale)-1));
5831
5832 if(!(flags&rNOCURSOR) && ((ComboBrush && !ComboBrushPause)||draw_mode==dm_alias) && inrect)
5833 {
5834 int mgridscale=16*mapscreen_single_scale;
5835 if(allowHideMouse)
5836 {
5837 if(arrowcursor)
5838 {
5839 arrowcursor = false;
5840 MouseSprite::set(ZQM_BLANK);
5841 }
5842 }
5843 else if(!arrowcursor)
5844 {
5845 arrowcursor = true;
5846 MouseSprite::set(ZQM_NORMAL);
5847 }
5848 ComboPosition pos = get_mapscreen_mouse_combo_pos();
5849 int32_t mx = pos.x * 16 * mapscreen_single_scale;
5850 int32_t my = pos.y * 16 * mapscreen_single_scale;
5851
5852 clear_bitmap(brushscreen);
5853 int32_t tempbw=BrushWidth;
5854 int32_t tempbh=BrushHeight;
5855
5856 if(draw_mode==dm_alias)
5857 {
5858 BrushWidth = combo_aliases[combo_apos].width+1;
5859 BrushHeight = combo_aliases[combo_apos].height+1;
5860 }
5861 else if(draw_mode == dm_cpool)
5862 {
5863 BrushWidth = BrushHeight = 1;
5864 combo_pool const& pool = combo_pools[combo_pool_pos];
5865 if(pool.valid())
5866 {
5867 int32_t cid = Combo;
5868 int8_t cset = CSet;
5869 pool.get_w_wrap(cid,cset,cpoolbrush_index/16); //divide to reduce speed
5870 put_combo(brushbmp,0,0,cid,cset,Flags&(cFLAGS|cWALK),0);
5871 }
5872 else clear_bitmap(brushbmp);
5873 }
5874 else if (draw_mode == dm_auto)
5875 {
5876 BrushWidth = BrushHeight = 1;
5877 }
5878
5879 stretch_blit(brushbmp, brushscreen, 0, 0, BrushWidth*16, BrushHeight*16, 0, 0, BrushWidth*mgridscale, BrushHeight*mgridscale);
5880 int float_offx = 0;
5881 int float_offy = 0;
5882
5883 if(FloatBrush)
5884 {
5885 float_offx = -SHADOW_DEPTH*mapscreen_single_scale;
5886 float_offy = -SHADOW_DEPTH*mapscreen_single_scale;
5887
5888 //shadow
5889 for(int x = 0; x < SHADOW_DEPTH*mapscreen_single_scale; ++x)
5890 for(int y = 0; y < (BrushHeight*mgridscale) + (SHADOW_DEPTH*mapscreen_single_scale); ++y)
5891 {
5892 if((((x^y)&1)==1) && y < 12*mgridscale)
5893 putpixel(brushscreen,x+(BrushWidth*mgridscale),y,vc(0));
5894 }
5895
5896 for(int x = 0; x < BrushWidth*mgridscale; ++x)
5897 for(int y = 0; y < SHADOW_DEPTH*mapscreen_single_scale; ++y)
5898 {
5899 if((((x^y)&1)==1) && x<16*mgridscale)
5900 putpixel(brushscreen,x,y+(BrushHeight*mgridscale),vc(0));
5901 }
5902 }
5903
5904 if(draw_mode==dm_alias)
5905 {
5906 combo_alias *combo = &combo_aliases[combo_apos];
5907
5908 if(BrushWidth > 1 && (alias_origin & 1)) //right-align
5909 float_offx -= (BrushWidth - 1) * mgridscale;
5910
5911 if(BrushHeight > 1 && (alias_origin & 2)) //bottom-align
5912 float_offy -= (BrushHeight - 1) * mgridscale;
5913 }
5914
5915 int bx = mapscreen_x + mx + float_offx + (showedges?(16*mapscreen_single_scale):0);
5916 int by = mapscreen_y + my + float_offy + (showedges?(16*mapscreen_single_scale):0);
5917 masked_blit(brushscreen, menu1, 0, 0, bx, by, 16*mgridscale, 11*mgridscale);
5918 BrushWidth=tempbw;
5919 BrushHeight=tempbh;
5920 }
5921 else
5922 {
5923 if(!arrowcursor)
5924 {
5925 MouseSprite::set(ZQM_NORMAL);
5926 arrowcursor = true;
5927 }
5928 }
5929
5930 if(ShowGrid)
5931 {
5932 int w = num_combos_width;
5933 int h = num_combos_height;
5934 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5935
5936 if(showedges)
5937 {
5938 w += 2;
5939 h += 2;
5940 }
5941
5942 for (int x = 1; x < w; x++)
5943 {
5944 vline(menu1, mapscreen_x + x*tile_size, mapscreen_y, mapscreen_y + (h*tile_size)-1, vc(GridColor));
5945 }
5946
5947 for (int y = 1; y < h; y++)
5948 {
5949 hline(menu1, mapscreen_x, mapscreen_y + y*tile_size, mapscreen_x + (w*tile_size)-1, vc(GridColor));
5950 }
5951 }
5952
5953 if(ShowScreenGrid)
5954 {
5955 int w = num_combos_width;
5956 int h = num_combos_height;
5957 double tile_size = 16.0 / Map.getViewSize() * mapscreen_screenunit_scale;
5958 int startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
5959 int starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
5960
5961 if(showedges)
5962 {
5963 w += 1;
5964 h += 1;
5965 }
5966
5967 int color = (GridColor+8)%16;
5968
5969 for (int x = 16; x < w; x+=16)
5970 {
5971 vline(menu1, startx + x*tile_size, mapscreen_y, starty + (h*tile_size)-1, vc(color));
5972 }
5973
5974 for (int y = 11; y < h; y+=11)
5975 {
5976 hline(menu1, startx, starty + y*tile_size, startx + (w*tile_size)-1, vc(color));
5977 }
5978 }
5979
5980 // Draw a black-yellow-black rect around the currently selected screen.
5981 if (ShowCurScreenOutline && Map.getViewSize() > 1)
5982 {
5983 int mw = 256 * mapscreen_single_scale;
5984 int mh = 176 * mapscreen_single_scale;
5985 int mx = (Map.getCurrScr() % 16) - (Map.getViewScr() % 16);
5986 int my = (Map.getCurrScr() / 16) - (Map.getViewScr() / 16);
5987 int x0 = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0) + mx * mw;
5988 int y0 = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0) + my * mh;
5989 dotted_rect(menu1, x0+1, y0+1, x0 + mw - 1, y0 + mh - 1, vc(1), vc(0));
5990 rect(menu1, x0, y0, x0 + mw, y0 + mh, vc(14));
5991 dotted_rect(menu1, x0-1, y0-1, x0 + mw + 1, y0 + mh + 1, vc(1), vc(0));
5992 }
5993
5994 // Map tabs
5995 font = get_custom_font(CFONT_GUI);
5996
5997 map_page[current_mappage].map=Map.getCurrMap();
5998 map_page[current_mappage].screen=Map.getCurrScr();
5999
6000 for(int32_t btn=0; btn<mappage_count; ++btn)
6001 {
6002 char tbuf[15];
6003 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
6004 draw_layer_button(menu1,map_page_bar[btn].x, map_page_bar[btn].y, map_page_bar[btn].w, map_page_bar[btn].h,tbuf,(btn==current_mappage?D_SELECTED:0));
6005 }
6006 }
6007 break;
6008 case rCOMBOS:
6009 {
6010 auto real_h = combolist_window.h;
6011 jwin_draw_frame(menu1,combolist_window.x,combolist_window.y,combolist_window.w,real_h, FR_WIN);
6012 rectfill(menu1,combolist_window.x+2,combolist_window.y+2,combolist_window.x+combolist_window.w-3,combolist_window.y+real_h-3,jwin_pal[jcBOX]);
6013
6014 //Scrollers
6015 for(int32_t c = 0; c < num_combo_cols; ++c)
6016 {
6017 auto& pos = combolistscrollers[c];
6018
6019 { //Scroll up
6020 auto& p = pos.subsquare(0);
6021 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6022
6023 for(int32_t i=0; i<3; i++)
6024 {
6025 hline(menu1, p.x+5-i, p.y+4+i, p.x+5+i, jwin_pal[jcBOXFG]);
6026 }
6027 }
6028
6029 { //Scroll down
6030 auto& p = pos.subsquare(1);
6031 jwin_draw_frame(menu1,p.x,p.y,p.w,p.h,FR_ETCHED);
6032
6033 for(int32_t i=0; i<3; i++)
6034 {
6035 hline(menu1,p.x+5-i,p.y+6-i, p.x+5+i, jwin_pal[jcBOXFG]);
6036 }
6037 }
6038 }
6039
6040 if(draw_mode==dm_alias)
6041 {
6042 if(LinkedScroll)
6043 {
6044 int tmp = current_comboalist;
6045 for(int q = tmp-1; q >= 0; --q)
6046 {
6047 combo_alistpos[q] = combo_alistpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6048 if(combo_alistpos[q] < 0)
6049 {
6050 tmp = 0;
6051 combo_alistpos[0] = 0;
6052 break;
6053 }
6054 }
6055 for(int q = tmp+1; q < num_combo_cols; ++q)
6056 combo_alistpos[q] = combo_alistpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6057 for(int q = 0; q < num_combo_cols; ++q)
6058 if(combo_apos >= combo_alistpos[q] && combo_apos < combo_alistpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6059 {
6060 current_comboalist = q;
6061 break;
6062 }
6063 }
6064 for(int32_t c = 0; c < num_combo_cols; ++c)
6065 {
6066 auto& pos = comboaliaslist[c];
6067 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6068 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6069 }
6070
6071 auto& prev = comboalias_preview;
6072 jwin_draw_frame(menu1, prev.x-2, prev.y-2, prev.w+4, prev.h+4,FR_DEEP);
6073
6074 BITMAP *prv = create_bitmap_ex(8,64,64);
6075 clear_bitmap(prv);
6076 int32_t scalefactor = 1;
6077
6078 for(int32_t j=0; j<num_combo_cols; ++j)
6079 {
6080 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6081 if(combo_alistpos[j] + per_page >= MAXCOMBOALIASES)
6082 combo_alistpos[j] = MAXCOMBOALIASES-per_page;
6083 auto& col = comboaliaslist[j];
6084 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6085 {
6086 draw_combo_alias_thumbnail(menu1, &combo_aliases[combo_alistpos[j]+i],
6087 (i%col.w)*col.xscale+col.x, (i/col.w)*col.yscale+col.y, col.xscale/16);
6088 }
6089
6090 if((combo_aliases[combo_apos].width>7)||(combo_aliases[combo_apos].height>7))
6091 {
6092 scalefactor=4;
6093 }
6094 else if((combo_aliases[combo_apos].width>3)||(combo_aliases[combo_apos].height>3))
6095 {
6096 scalefactor=2;
6097 }
6098
6099
6100 if(j==current_comboalist)
6101 {
6102 stretch_blit(brushbmp, prv, 0,0,scalefactor*64,zc_min(scalefactor*64,176),0,0,64,scalefactor==4?44:64);
6103 blit(prv,menu1,0,0,comboalias_preview.x,comboalias_preview.y,comboalias_preview.w,comboalias_preview.h);
6104
6105 int32_t rect_pos=combo_apos-combo_alistpos[current_comboalist];
6106
6107 if((rect_pos>=0)&&(rect_pos<(combo_alistpos[current_comboalist]+(col.w*col.h))))
6108 {
6109 int selw = col.xscale;
6110 int selh = col.yscale;
6111 int x1 = (rect_pos&(col.w-1))*col.xscale+col.x;
6112 int y1 = (rect_pos/col.w)*col.yscale+col.y;
6113 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6114 }
6115 }
6116 }
6117
6118 destroy_bitmap(prv);
6119 }
6120 else if(draw_mode==dm_cpool)
6121 {
6122 if(LinkedScroll)
6123 {
6124 int tmp = current_cpoollist;
6125 for(int q = tmp-1; q >= 0; --q)
6126 {
6127 combo_pool_listpos[q] = combo_pool_listpos[q+1]-(comboaliaslist[q].w*comboaliaslist[q].h);
6128 if(combo_pool_listpos[q] < 0)
6129 {
6130 tmp = 0;
6131 combo_pool_listpos[0] = 0;
6132 break;
6133 }
6134 }
6135 for(int q = tmp+1; q < num_combo_cols; ++q)
6136 combo_pool_listpos[q] = combo_pool_listpos[q-1]+(comboaliaslist[q-1].w*comboaliaslist[q-1].h);
6137 for(int q = 0; q < num_combo_cols; ++q)
6138 if(combo_pool_pos >= combo_pool_listpos[q] && combo_pool_pos < combo_pool_listpos[q] + (comboaliaslist[q].w*comboaliaslist[q].h))
6139 {
6140 current_cpoollist = q;
6141 break;
6142 }
6143 }
6144 for(int32_t c = 0; c < num_combo_cols; ++c)
6145 {
6146 auto& pos = comboaliaslist[c];
6147 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6148 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*comboaliaslist[c].xscale)+4,(pos.h*comboaliaslist[c].yscale)+4,FR_DEEP);
6149 }
6150
6151 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6152 {
6153 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6154 if(combo_pool_listpos[j] + per_page >= MAXCOMBOPOOLS)
6155 combo_pool_listpos[j] = MAXCOMBOPOOLS-per_page;
6156 for(int32_t i=0; i<(comboaliaslist[j].w*comboaliaslist[j].h); i++)
6157 {
6158 int32_t cid=-1; int8_t cs=CSet;
6159 combo_pool const& cp = combo_pools[combo_pool_listpos[j]+i];
6160
6161 auto& list = comboaliaslist[j];
6162 if(cp.get_w(cid,cs,0) && !combobuf[cid].tile)
6163 {
6164 cid = -1; //no tile to draw
6165 }
6166 auto cx = (i%list.w)*list.xscale+list.x;
6167 auto cy = (i/list.w)*list.yscale+list.y;
6168 put_combo(menu1,cx,cy,cid,cs,Flags&(cFLAGS|cWALK),0,list.xscale/16);
6169 }
6170 }
6171 int32_t rect_pos=combo_pool_pos-combo_pool_listpos[current_cpoollist];
6172
6173 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_cpoollist]+(comboaliaslist[current_cpoollist].w*comboaliaslist[current_cpoollist].h))))
6174 {
6175 int selw = comboaliaslist[current_cpoollist].xscale;
6176 int selh = comboaliaslist[current_cpoollist].yscale;
6177 int x1 = (rect_pos&(comboaliaslist[current_cpoollist].w-1))*comboaliaslist[current_cpoollist].xscale+comboaliaslist[current_cpoollist].x;
6178 int y1 = (rect_pos/comboaliaslist[current_cpoollist].w)*comboaliaslist[current_cpoollist].yscale+comboaliaslist[current_cpoollist].y;
6179 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6180 }
6181
6182 //Handle Preview
6183 combo_pool const& cpool = combo_pools[combo_pool_pos];
6184
6185 int32_t cid; int8_t cs;
6186 size_t total = weighted_cpool ? cpool.getTotalWeight() : cpool.combos.size();
6187 size_t ind = 0;
6188 size_t indw = combopool_preview.w/16;
6189 size_t indh = combopool_preview.h/16;
6190 size_t rows = total ? vbound(total/indw,1,indh) : 0;
6191 if (is_compact)
6192 rows = vbound(rows, 1, 3);
6193 else
6194 rows = vbound(rows, 1, 4);
6195 size_t real_height = rows*16;
6196
6197 cpool_prev_visible = rows > 0;
6198 if(rows)
6199 {
6200 jwin_draw_frame(menu1,combopool_preview.x-2,combopool_preview.y-2,
6201 combopool_preview.w+4,real_height+4,FR_DEEP);
6202 rectfill(menu1,combopool_preview.x,combopool_preview.y,
6203 combopool_preview.x+combopool_preview.w-1,
6204 combopool_preview.y+real_height-1,vc(0));
6205 draw_text_button(menu1,combopool_prevbtn.x,combopool_prevbtn.y,
6206 combopool_prevbtn.w,combopool_prevbtn.h,
6207 weighted_cpool ? "Weighted" : "Unweighted",vc(1),vc(14),0,true);
6208 if(!is_compact)
6209 textprintf_ex(menu1,font,combopool_prevbtn.x+combopool_prevbtn.w+5,
6210 combopool_prevbtn.y,jwin_pal[jcBOXFG],-1,"Preview");
6211 for(auto y = 0; y < real_height; y += 16)
6212 {
6213 for(auto x = 0; x < combopool_preview.w; x += 16, ++ind)
6214 {
6215 auto nx = combopool_preview.x+x, ny = combopool_preview.y+y;
6216 if(ind < total)
6217 {
6218 cs = CSet;
6219 if(weighted_cpool
6220 ? cpool.get_w(cid,cs,ind)
6221 : cpool.get_ind(cid,cs,ind))
6222 {
6223 put_combo(menu1,nx,ny,cid,cs,Flags&(cFLAGS|cWALK),0);
6224 continue;
6225 }
6226 }
6227 //No combo to display
6228 xout(menu1, nx, ny, nx+15, ny+15, vc(15));
6229 }
6230 }
6231 }
6232 }
6233 else if (draw_mode == dm_auto)
6234 {
6235 if (LinkedScroll)
6236 {
6237 int tmp = current_cautolist;
6238 for (int q = tmp - 1; q >= 0; --q)
6239 {
6240 combo_auto_listpos[q] = combo_auto_listpos[q + 1] - (comboaliaslist[q].w * comboaliaslist[q].h);
6241 if (combo_auto_listpos[q] < 0)
6242 {
6243 tmp = 0;
6244 combo_auto_listpos[0] = 0;
6245 break;
6246 }
6247 }
6248 for (int q = tmp + 1; q < num_combo_cols; ++q)
6249 combo_auto_listpos[q] = combo_auto_listpos[q - 1] + (comboaliaslist[q - 1].w * comboaliaslist[q - 1].h);
6250 for (int q = 0; q < num_combo_cols; ++q)
6251 if (combo_auto_pos >= combo_auto_listpos[q] && combo_auto_pos < combo_auto_listpos[q] + (comboaliaslist[q].w * comboaliaslist[q].h))
6252 {
6253 current_cautolist = q;
6254 break;
6255 }
6256 }
6257 for (int32_t c = 0; c < num_combo_cols; ++c)
6258 {
6259 auto& pos = comboaliaslist[c];
6260 rectfill(menu1, pos.x, pos.y, pos.x + (pos.w * pos.xscale) - 1, pos.y + (pos.h * pos.yscale) - 1, 0);
6261 jwin_draw_frame(menu1, pos.x - 2, pos.y - 2, (pos.w * comboaliaslist[c].xscale) + 4, (pos.h * comboaliaslist[c].yscale) + 4, FR_DEEP);
6262 }
6263
6264 for (int32_t j = 0; j < num_combo_cols; ++j) //the actual panes
6265 {
6266 auto per_page = (comboaliaslist[j].w * comboaliaslist[j].h);
6267 if(combo_auto_listpos[j] + per_page >= MAXAUTOCOMBOS)
6268 combo_auto_listpos[j] = MAXAUTOCOMBOS-per_page;
6269 for (int32_t i = 0; i < (comboaliaslist[j].w * comboaliaslist[j].h); i++)
6270 {
6271 int32_t cid = -1; int8_t cs = CSet;
6272 combo_auto const& ca = combo_autos[combo_auto_listpos[j] + i];
6273
6274 auto& list = comboaliaslist[j];
6275 cid = ca.getDisplay();
6276 if (cid == 0)
6277 cid = -1;
6278 auto cx = (i % list.w) * list.xscale + list.x;
6279 auto cy = (i / list.w) * list.yscale + list.y;
6280 put_combo(menu1, cx, cy, cid, cs, Flags & (cFLAGS | cWALK), 0, list.xscale / 16);
6281 put_autocombo_engravings(menu1, ca, combo_auto_listpos[j] + i == combo_auto_pos, cx, cy, list.xscale / 16);
6282 }
6283 }
6284 int32_t rect_pos = combo_auto_pos - combo_auto_listpos[current_cautolist];
6285
6286 if ((rect_pos >= 0) && (rect_pos < (combo_auto_listpos[current_cautolist] + (comboaliaslist[current_cautolist].w * comboaliaslist[current_cautolist].h))))
6287 {
6288 int selw = comboaliaslist[current_cautolist].xscale;
6289 int selh = comboaliaslist[current_cautolist].yscale;
6290 int x1 = (rect_pos & (comboaliaslist[current_cautolist].w - 1)) * comboaliaslist[current_cautolist].xscale + comboaliaslist[current_cautolist].x;
6291 int y1 = (rect_pos / comboaliaslist[current_cautolist].w) * comboaliaslist[current_cautolist].yscale + comboaliaslist[current_cautolist].y;
6292 safe_rect(menu1, x1, y1, x1 + selw - 1, y1 + selh - 1, vc(CmbCursorCol), 2);
6293
6294 combo_auto const& ca = combo_autos[combo_auto_pos];
6295 put_autocombo_engravings(menu1, ca, true, x1, y1, selw / 16);
6296 }
6297 }
6298 else
6299 {
6300 if(LinkedScroll)
6301 {
6302 int tmp = current_combolist;
6303 for(int q = tmp-1; q >= 0; --q)
6304 {
6305 First[q] = First[q+1]-(combolist[q].w*combolist[q].h);
6306 if(First[q] < 0)
6307 {
6308 tmp = 0;
6309 First[0] = 0;
6310 break;
6311 }
6312 }
6313 for(int q = tmp+1; q < num_combo_cols; ++q)
6314 First[q] = First[q-1]+(combolist[q-1].w*combolist[q-1].h);
6315 for(int q = 0; q < num_combo_cols; ++q)
6316 if(Combo >= First[q] && Combo < First[q] + (combolist[q].w*combolist[q].h))
6317 {
6318 current_combolist = q;
6319 break;
6320 }
6321 }
6322 for(int32_t c = 0; c < num_combo_cols; ++c)
6323 {
6324 auto& pos = combolist[c];
6325 rectfill(menu1,pos.x,pos.y,pos.x+(pos.w*pos.xscale)-1,pos.y+(pos.h*pos.yscale)-1,0);
6326 jwin_draw_frame(menu1,pos.x-2,pos.y-2,(pos.w*pos.xscale)+4,(pos.h*pos.yscale)+4,FR_DEEP);
6327 }
6328
6329 int32_t drawmap, drawscr;
6330 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6331 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6332
6333 for(int32_t j=0; j<num_combo_cols; ++j)
6334 {
6335 auto per_page = (combolist[j].w * combolist[j].h);
6336 if(First[j] + per_page >= MAXCOMBOS)
6337 First[j] = MAXCOMBOS-per_page;
6338 for(int32_t i=0; i<(combolist[j].w*combolist[j].h); i++)
6339 {
6340 put_combo(menu1,(i%combolist[j].w)*combolist[j].xscale+combolist[j].x,
6341 (i/combolist[j].w)*combolist[j].yscale+combolist[j].y,
6342 i+First[j],CSet,Flags&(cFLAGS|cWALK),0,combolist[j].xscale/16);
6343 }
6344 }
6345
6346 int32_t rect_pos=Combo-First[current_combolist];
6347
6348 if((rect_pos>=0)&&(rect_pos<(combo_pool_listpos[current_combolist]+(combolist[current_combolist].w*combolist[current_combolist].h))))
6349 {
6350 int selw = (AutoBrush?BrushWidth:1)*combolist[current_combolist].xscale;
6351 int selh = (AutoBrush?BrushHeight:1)*combolist[current_combolist].yscale;
6352 int x1 = (rect_pos&(combolist[current_combolist].w-1))*combolist[current_combolist].xscale+combolist[current_combolist].x;
6353 int y1 = (rect_pos/combolist[current_combolist].w)*combolist[current_combolist].yscale+combolist[current_combolist].y;
6354 safe_rect(menu1,x1,y1,x1+selw-1,y1+selh-1,vc(CmbCursorCol),2);
6355 }
6356 }
6357 }
6358 break;
6359 case rCOMBO:
6360 {
6361 int32_t drawmap, drawscr;
6362 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
6363 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
6364
6365 // Combo preview
6366 int32_t cid = Combo; int8_t cs = CSet;
6367 if(draw_mode == dm_alias)
6368 {
6369 cid = combo_aliases[combo_apos].combos[0];
6370 cs = wrap(combo_aliases[combo_apos].csets[0]+alias_cset_mod, 0, 13);
6371 }
6372 else if(draw_mode == dm_cpool)
6373 {
6374 combo_pool const& cpool = combo_pools[combo_pool_pos];
6375 cid = 0;
6376 cpool.get_w(cid,cs,0);
6377 }
6378 else if (draw_mode == dm_auto)
6379 {
6380 combo_auto const& cauto = combo_autos[combo_auto_pos];
6381 cid = cauto.getDisplay();
6382 }
6383 static BITMAP *combo_preview_bmp=create_bitmap_ex(8,32,32);
6384 static BITMAP *cycle_preview_bmp=create_bitmap_ex(8,32,32);
6385 // Combo
6386 put_combo(combo_preview_bmp,0,0,cid,cs,Flags&(cFLAGS|cWALK),0);
6387 jwin_draw_frame(menu1,combo_preview.x-2,combo_preview.y-2,combo_preview.w+4,combo_preview.h+4, FR_DEEP);
6388 stretch_blit(combo_preview_bmp, menu1, 0, 0, 16, 16, combo_preview.x, combo_preview.y, combo_preview.w, combo_preview.h);
6389
6390 comboprev_buf[0] = 0;
6391 comboprev_buf2[0] = 0;
6392 if(draw_mode == dm_cpool)
6393 {
6394 sprintf(comboprev_buf,"Pool: %d",combo_pool_pos);
6395 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6396 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],comboprev_buf,2,&combo_preview_text1);
6397 }
6398 else if (draw_mode == dm_auto)
6399 {
6400 GUI::ListData ac_types = GUI::ZCListData::autocombotypes();
6401 std::string type_name = ac_types.findText(combo_autos[combo_auto_pos].getType());
6402 if (is_compact)
6403 sprintf(comboprev_buf, "AC: %d CS: %d\n%s", combo_auto_pos, CSet, type_name.c_str());
6404 else
6405 sprintf(comboprev_buf, "Auto: %d CSet: %d\n%s\nEntries: %d", combo_auto_pos, CSet, type_name.c_str(), int32_t(combo_autos[combo_auto_pos].combos.size()));
6406 int x = combo_preview_text1.x + (combo_preview_text1.w * combo_preview_text1.xscale);
6407 textbox_out(menu1, txfont, x, combo_preview_text1.y, jwin_pal[jcBOXFG], jwin_pal[jcBOX], comboprev_buf, 2, &combo_preview_text1);
6408 }
6409 else if(draw_mode != dm_alias)
6410 {
6411 int x = combo_preview_text1.x+(combo_preview_text1.w*combo_preview_text1.xscale);
6412
6413 char shortbuf[512];
6414 char buf[256];
6415 strcpy(buf,combo_class_buf[combobuf[Combo].type].name);
6416 sprintf(comboprev_buf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6417 int ind = strlen(buf)-1;
6418 int x2 = x;
6419 if(x2 - text_length(txfont, buf) <= combolist_window.x)
6420 {
6421 auto dotlen = text_length(txfont, "..");
6422 x2 -= dotlen;
6423 while(x2 - text_length(txfont, buf) <= combolist_window.x)
6424 {
6425 if(ind < 0) break;
6426 buf[ind--] = '\0';
6427 }
6428 while(ind >= 0 && buf[ind] == ' ')
6429 buf[ind--] = 0; //trim spaces
6430 strcat(buf, "..");
6431 }
6432
6433 if(is_compact)
6434 {
6435 char b2[256];
6436 sprintf(b2, "Combo %d CS %d", Combo, CSet);
6437 if(x-text_length(txfont, b2) <= combolist_window.x)
6438 sprintf(b2, "Cmb %d CS %d", Combo, CSet);
6439 sprintf(shortbuf,"%s\n%s",b2,buf);
6440 }
6441 else sprintf(shortbuf,"Combo: %d\nCSet: %d\n%s",Combo,CSet,buf);
6442 textbox_out(menu1,txfont,x,combo_preview_text1.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,2,&combo_preview_text1);
6443 }
6444
6445 // Cycle
6446 if(!is_compact)
6447 {
6448 int32_t NextCombo = combobuf[Combo].nextcombo;
6449 int32_t NextCSet = combobuf[Combo].nextcset;
6450 if(combobuf[Combo].animflags & AF_CYCLEUNDERCOMBO)
6451 {
6452 mapscr* scr = Map.CurrScr();
6453 NextCombo = scr->undercombo;
6454 NextCSet = scr->undercset;
6455 }
6456 if(combobuf[Combo].animflags & AF_CYCLENOCSET)
6457 NextCSet = CSet;
6458 bool normal_dm = draw_mode != dm_alias && draw_mode != dm_cpool && draw_mode != dm_auto;
6459 jwin_draw_frame(menu1,combo_preview2.x-2,combo_preview2.y-2,combo_preview2.w+4,combo_preview2.h+4, FR_DEEP);
6460 if(NextCombo>0 && normal_dm)
6461 {
6462 put_combo(cycle_preview_bmp,0,0,NextCombo,NextCSet,Flags&(cFLAGS|cWALK),0);
6463
6464 if(Flags&cWALK) put_walkflags(cycle_preview_bmp,0,0,NextCombo,0);
6465
6466 if(Flags&cFLAGS) put_flags(cycle_preview_bmp,0,0,NextCombo,0,cFLAGS,0);
6467
6468 stretch_blit(cycle_preview_bmp, menu1, 0, 0, 16, 16, combo_preview2.x, combo_preview2.y, combo_preview2.w, combo_preview2.h);
6469 }
6470 else
6471 {
6472 if (InvalidBG == 2)
6473 {
6474 draw_checkerboard(menu1, combo_preview2.x, combo_preview2.y, 32);
6475 }
6476 else if(InvalidBG == 1)
6477 {
6478 for(int32_t dy=0; dy<combo_preview2.w; dy++)
6479 {
6480 for(int32_t dx=0; dx<combo_preview2.w; dx++)
6481 {
6482 menu1->line[dy+combo_preview2.y][dx+combo_preview2.x]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6483 }
6484 }
6485 }
6486 else
6487 {
6488 rectfill(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(0));
6489 safe_rect(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6490 line(menu1, combo_preview2.x,combo_preview2.y, combo_preview2.x+32,combo_preview2.y+combo_preview2.h,vc(15));
6491 line(menu1, combo_preview2.x,combo_preview2.y+combo_preview2.h, combo_preview2.x+32,combo_preview2.y,vc(15));
6492 }
6493 }
6494
6495 if(normal_dm)
6496 {
6497 char shortbuf[512];
6498 char buf[256];
6499 strcpy(buf,combo_class_buf[combobuf[NextCombo].type].name);
6500 sprintf(comboprev_buf2, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6501 int ind = strlen(buf)-1;
6502 int x2 = combo_preview_text2.x;
6503 if(x2 + text_length(txfont, buf) > zq_screen_w-2)
6504 {
6505 auto dotlen = text_length(txfont, "..");
6506 x2 += dotlen;
6507 while(x2 + text_length(txfont, buf) > zq_screen_w-2)
6508 {
6509 if(ind < 0) break;
6510 buf[ind--] = '\0';
6511 }
6512 while(ind >= 0 && buf[ind] == ' ')
6513 buf[ind--] = 0; //trim spaces
6514 strcat(buf, "..");
6515 }
6516
6517 sprintf(shortbuf, "Cycle: %d\nCSet: %d\n%s", NextCombo, NextCSet, buf);
6518 textbox_out(menu1,txfont,combo_preview_text2.x,combo_preview_text2.y,jwin_pal[jcBOXFG],jwin_pal[jcBOX],shortbuf,0,&combo_preview_text2);
6519 }
6520 }
6521
6522 font = get_zc_font(font_lfont_l);
6523 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
6524 draw_text_button(menu1,combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<",vc(1),vc(14),0,true);
6525 }
6526 break;
6527 case rFAVORITES:
6528 {
6529 font = get_zc_font(font_lfont_l);
6530
6531 jwin_draw_frame(menu1,favorites_window.x,favorites_window.y,favorites_window.w,favorites_window.h, FR_WIN);
6532 rectfill(menu1,favorites_window.x+2,favorites_window.y+2,favorites_window.x+favorites_window.w-3,favorites_window.y+favorites_window.h-3,jwin_pal[jcBOX]);
6533 jwin_draw_frame(menu1,favorites_list.x-2,favorites_list.y-2,(favorites_list.w*favorites_list.xscale)+4,(favorites_list.h*favorites_list.yscale)+4, FR_DEEP);
6534 rectfill(menu1,favorites_list.x,favorites_list.y,favorites_list.x+(favorites_list.w*favorites_list.xscale)-1,favorites_list.y+(favorites_list.h*favorites_list.yscale)-1,jwin_pal[jcBOXFG]);
6535
6536 textprintf_ex(menu1,get_zc_font(font_lfont_l),favorites_list.x-2,favorites_list.y-15,jwin_pal[jcBOXFG],-1,is_compact ? "Favorites" : "Favorite Combos");
6537 BITMAP* subb = create_bitmap_ex(8,16,16);
6538
6539 for(int32_t col=0; col<favorites_list.w; ++col)
6540 {
6541 for(int32_t row=0; row<favorites_list.h; ++row)
6542 {
6543 auto i = (row*FAVORITECOMBO_PER_ROW)+col+FAVORITECOMBO_PER_PAGE*FavoriteComboPage;
6544 auto& sqr = favorites_list.subsquare(col,row);
6545 if(i >= MAXFAVORITECOMBOS || favorite_combos[i]==-1)
6546 {
6547 if (InvalidBG == 2)
6548 {
6549 draw_checkerboard(menu1, sqr.x, sqr.y, sqr.w);
6550 }
6551 else if(InvalidBG == 1)
6552 {
6553 for(int32_t dy=0; dy<sqr.h; dy++)
6554 {
6555 for(int32_t dx=0; dx<sqr.w; dx++)
6556 {
6557 menu1->line[sqr.y+dy][sqr.x+dx]=vc((((zc_oldrand()%100)/50)?0:8)+(((zc_oldrand()%100)/50)?0:7));
6558 }
6559 }
6560 }
6561 else
6562 {
6563 xout(menu1, sqr.x, sqr.y, sqr.x+sqr.w-1, sqr.y+sqr.h-1, vc(15), vc(0));
6564 }
6565 }
6566 else
6567 {
6568 clear_bitmap(subb);
6569 bool repos = combotile_override_x < 0 && combotile_override_y < 0;
6570
6571 switch(favorite_combo_modes[i])
6572 {
6573 case dm_alias:
6574 draw_combo_alias_thumbnail(subb, &combo_aliases[favorite_combos[i]], 0, 0, 1);
6575 if (ShowFavoriteComboModes)
6576 put_engraving(subb, 0, 0, 0x3E, 1);
6577 break;
6578 case dm_cpool:
6579 {
6580 int32_t cid = -1; int8_t cs = CSet;
6581 combo_pool const& cp = combo_pools[favorite_combos[i]];
6582
6583 if (cp.get_w(cid, cs, 0) && !combobuf[cid].tile)
6584 cid = -1; //no tile to draw
6585 put_combo(subb, 0, 0, cid, cs, 0, 0);
6586 if (ShowFavoriteComboModes)
6587 put_engraving(subb, 0, 0, 0x3D, 1);
6588 break;
6589 }
6590 case dm_auto:
6591 {
6592 int32_t cid = -1; int8_t cs = CSet;
6593 combo_auto const& ca = combo_autos[favorite_combos[i]];
6594
6595 cid = ca.getDisplay();
6596 if (cid == 0)
6597 cid = -1;
6598 put_combo(subb, 0, 0, cid, cs, 0, 0);
6599 if (ShowFavoriteComboModes)
6600 put_engraving(subb, 0, 0, 0x3C, 1);
6601 break;
6602 }
6603 default:
6604 if (repos)
6605 {
6606 combotile_override_x = sqr.x + (sqr.w - 16) / 2;
6607 combotile_override_y = sqr.y + (sqr.h - 16) / 2;
6608 }
6609 put_combo(subb, 0, 0, favorite_combos[i], CSet, Flags & (cFLAGS | cWALK), 0);
6610 if (repos) combotile_override_x = combotile_override_y = -1;
6611 }
6612 stretch_blit(subb, menu1, 0, 0, 16, 16, sqr.x, sqr.y, sqr.w, sqr.h);
6613 }
6614 }
6615 }
6616
6617 destroy_bitmap(subb);
6618
6619 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
6620 if(!is_compact)
6621 textprintf_right_ex(menu1, get_zc_font(font_lfont_l), favorites_pgleft.x - 2, favorites_pgleft.y, jwin_pal[jcBOXFG], -1, "%d/9", FavoriteComboPage + 1);
6622
6623 draw_text_button(menu1, favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-", vc(1), vc(14), 0, true);
6624 draw_text_button(menu1, favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->", vc(1), vc(14), 0, true);
6625 draw_text_button(menu1,favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6626 draw_text_button(menu1,favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X",vc(1),vc(14),0,true);
6627 draw_text_button(menu1,favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?",vc(1),vc(14),0,true);
6628 }
6629 break;
6630 case rCOMMANDS:
6631 {
6632 jwin_draw_frame(menu1,commands_window.x,commands_window.y,commands_window.w,commands_window.h, FR_WIN);
6633 rectfill(menu1,commands_window.x+2,commands_window.y+2,commands_window.x+commands_window.w-3,commands_window.y+commands_window.h-3,jwin_pal[jcBOX]);
6634 jwin_draw_frame(menu1,commands_list.x-2,commands_list.y-2,(commands_list.w*commands_list.xscale)+4,(commands_list.h*commands_list.yscale)+4, FR_DEEP);
6635 rectfill(menu1,commands_list.x,commands_list.y,commands_list.x+(commands_list.w*commands_list.xscale)-1,commands_list.y+(commands_list.h*commands_list.yscale)-1,jwin_pal[jcBOXFG]);
6636 font=get_custom_font(CFONT_FAVCMD);
6637
6638 for(int32_t cmd=0; cmd<(commands_list.w*commands_list.h); ++cmd)
6639 {
6640 uint hkey = favorite_commands[cmd];
6641 draw_layer_button(menu1,
6642 (cmd%commands_list.w)*commands_list.xscale+commands_list.x,
6643 (cmd/commands_list.w)*commands_list.yscale+commands_list.y,
6644 commands_list.xscale,
6645 commands_list.yscale,
6646 get_hotkey_name(hkey),
6647 (selected_hotkey(hkey)?D_SELECTED:0) | (disabled_hotkey(hkey)?D_DISABLED:0));
6648 }
6649
6650 font = get_zc_font(font_lfont_l);
6651 if(commands_txt.x > 0)
6652 {
6653 gui_textout_ln(menu1, get_zc_font(font_lfont_l), (ucc*)"Favorite Commands", commands_txt.x, commands_txt.y, jwin_pal[jcBOXFG], -1, 0);
6654 }
6655
6656 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
6657 draw_text_button(menu1,commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+",vc(1),vc(14),0,true);
6658 draw_text_button(menu1,commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X",vc(1),vc(14),0,true);
6659 draw_text_button(menu1,commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?",vc(1),vc(14),0,true);
6660 }
6661 break;
6662 }
6663 font = tfont;
6664 }
6665
6666 bool pause_refresh = true;
6667 bool is_refreshing = false;
6668 10 void refresh(int32_t flags, bool update)
6669 {
6670
1/2
✓ Branch 0 taken 10 times.
✗ Branch 1 not taken.
10 if(pause_refresh) return;
6671 static bool refreshing = false;
6672
6673 int num_screens_to_draw = Map.getViewSize();
6674
6675 bool earlyret = refreshing;
6676 is_refreshing = refreshing = true;
6677 //^ These prevent recursive calls from updating the screen early
6678
6679 bool zoom_delay = (zoomed_minimap && flags != rSCRMAP);
6680 if(zoom_delay)
6681 flags &= ~rSCRMAP;
6682
6683 if(flags&rCLEAR)
6684 {
6685 //magic pink = 0xED
6686 //system black = vc(0)
6687 //Clear a4 menu
6688 clear_to_color(menu1,jwin_pal[jcBOX]);
6689
6690 //Clears should refresh everything!
6691 flags |= rALL;
6692 }
6693
6694 if(flags&rSCRMAP)
6695 draw_screenunit(rSCRMAP,flags);
6696
6697 if(flags&rMAP)
6698 draw_screenunit(rMAP,flags);
6699
6700 if((flags&rCOMBOS) || (draw_mode == dm_cpool && (flags&rFAVORITES)))
6701 draw_screenunit(rCOMBOS,flags);
6702
6703 if(flags&(rCOMBO|rCOMBOS))
6704 draw_screenunit(rCOMBO,flags);
6705
6706 if(flags&rMENU)
6707 drawpanel();
6708
6709 if(flags&rFAVORITES)
6710 draw_screenunit(rFAVORITES,flags);
6711
6712 if(flags&rCOMMANDS)
6713 draw_screenunit(rCOMMANDS,flags);
6714
6715 FONT* tfont = font;
6716 font = get_custom_font(CFONT_GUI);
6717 jwin_draw_frame(menu1,layer_panel.x,layer_panel.y,layer_panel.w,layer_panel.h,FR_DEEP);
6718 rectfill(menu1,layer_panel.x,layer_panel.y,layer_panel.x+layer_panel.w-1,layer_panel.y+layer_panel.h-1,jwin_pal[jcBOX]);
6719
6720 for(int32_t i=0; i<=6; ++i)
6721 {
6722 char tbuf[15];
6723
6724 if (i>0 && mapscreen_valid_layers[i - 1] && num_screens_to_draw == 1)
6725 {
6726 if(is_compact)
6727 sprintf(tbuf, "%s%d %d:%02X", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6728 else sprintf(tbuf, "%s%d (%d:%02X)", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
6729 }
6730 else
6731 {
6732 sprintf(tbuf, "%s%d", (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"", i);
6733 }
6734
6735 int32_t spacing_offs = is_compact ? 2 : 10;
6736 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
6737 int32_t ry = layer_panel.y;
6738 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
6739 draw_layer_button(menu1, rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf, CurrentLayer==i? D_SELECTED : ( i > 0 && !mapscreen_valid_layers[i-1]) ? D_DISABLED : 0);
6740 draw_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]!=0);
6741 }
6742
6743 font=tfont;
6744
6745 // } //if(true)
6746 if(zq_showpal)
6747 {
6748 for(int32_t i=0; i<256; i++)
6749 {
6750 rectfill(menu1,((i&15)<<2)+256,((i>>4)<<2)+176,((i&15)<<2)+259,((i>>4)<<2)+179,i);
6751 }
6752 }
6753 { //Show top-left info
6754 size_t maxwid = (mapscreen_screenunit_scale*mapscreenbmp->w)-1;
6755 size_t maxhei = (mapscreen_screenunit_scale*mapscreenbmp->w);
6756 set_clip_rect(menu1,mapscreen_x,mapscreen_y,mapscreen_x+maxwid-1,mapscreen_y+maxhei-1);
6757 FONT* showfont = get_custom_font(CFONT_INFO);
6758 int showfont_h = text_height(showfont);
6759 int32_t ypos = mapscreen_y;
6760 if(prv_mode)
6761 {
6762 textout_shadowed_ex(menu1,showfont,"Preview Mode",0,ypos,vc(15),vc(0),infobg?vc(0):-1);
6763 ypos += showfont_h+1;
6764 if(prv_twon)
6765 {
6766 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"T Warp=%d tics", Map.get_prvtime());
6767 ypos += showfont_h+1;
6768 }
6769 }
6770 if(ShowFPS)
6771 {
6772 textprintf_shadowed_ex(menu1,showfont,0,ypos,vc(15),vc(0),infobg?vc(0):-1,"FPS: %3d",lastfps);
6773 ypos += showfont_h+1;
6774 }
6775
6776 if(ShowFFScripts && !prv_mode)
6777 {
6778 word num_ffcs = Map.CurrScr()->numFFC();
6779 for(word i=0; i< num_ffcs; i++)
6780 {
6781 if(ypos+showfont_h-1 > map_page_bar[0].y)
6782 break;
6783 if(Map.CurrScr()->ffcs[i].script && Map.CurrScr()->ffcs[i].data)
6784 {
6785 textout_shadowed_ex(menu1, showfont, ffcmap[Map.CurrScr()->ffcs[i].script-1].scriptname.substr(0,300).c_str(),0,ypos,vc(showxypos_ffc==i ? 14 : 15),vc(0),infobg?vc(0):-1);
6786 ypos+=showfont_h+1;
6787 }
6788 }
6789 }
6790 clear_clip_rect(menu1);
6791 if(prv_mode)
6792 do_previewtext();
6793 }
6794 // Show Errors & Details
6795 //This includes the presence of: Screen State Carryover, Timed Warp, Maze Path, the 'Sideview Gravity', 'Invisible Hero',
6796 //'Save Screen', 'Continue Here' and 'Treat As..' Screen Flags,
6797 // the String, every Room Type and Catch All, and all four Tile and Side Warps.
6798 if(!prv_mode && ShowInfo)
6799 {
6800 int32_t i=0;
6801 char buf[2048];
6802
6803 // Start with general information
6804 if(Map.CurrScr()->flags3&fINVISHERO)
6805 {
6806 sprintf(buf,"Invisible Hero");
6807 show_screen_error(buf,i++,vc(15));
6808 }
6809
6810 if(Map.getLayerTargetMap() > 0)
6811 {
6812 Map.setlayertarget(); //Now the text does not carry over when changing maps, but shifting back, it does not **re-appear** until you change screens.
6813 //It was also required to set some updates in onDecMap and onIncMap. #
6814 //This fixes Screen Info not displaying properly when changing maps. -Z
6815 //Needed to refresh the screen info. -Z ( 26th March, 2019 )
6816 int32_t m = Map.getLayerTargetMultiple();
6817 sprintf(buf,"Used as a layer by screen %d:%02X",Map.getLayerTargetMap(),Map.getLayerTargetScr());
6818 char buf2[24];
6819
6820 if(m>0)
6821 {
6822 sprintf(buf2," and %d other%s",m,m>1?"s":"");
6823 strcat(buf,buf2);
6824 }
6825
6826 show_screen_error(buf,i++,vc(15));
6827 }
6828
6829 if(Map.CurrScr()->nextmap)
6830 {
6831 sprintf(buf,"Screen State carries over to %d:%02X",Map.CurrScr()->nextmap,Map.CurrScr()->nextscr);
6832 show_screen_error(buf,i++,vc(15));
6833 }
6834
6835 if(Map.CurrScr()->timedwarptics)
6836 {
6837 sprintf(buf,"%s%sTimed Warp: %s",(Map.CurrScr()->flags4&fTIMEDDIRECT)?"Direct ":"",(Map.CurrScr()->flags5&fRANDOMTIMEDWARP)?"Random ":"",ticksstr(Map.CurrScr()->timedwarptics));
6838 show_screen_error(buf,i++,vc(15));
6839 }
6840
6841 if(Map.CurrScr()->flags&fMAZE)
6842 {
6843 sprintf(buf,"Maze Path: %s (Exit %s)",pathstr(Map.CurrScr()->path),mazedirstr[Map.CurrScr()->exitdir]);
6844 show_screen_error(buf,i++,vc(15));
6845 }
6846
6847 bool continuescreen = false, savecombo = false;
6848
6849 if(Map.CurrScr()->flags4&fAUTOSAVE)
6850 {
6851 sprintf(buf,"Automatic Save%s Screen", (Map.CurrScr()->flags6&fCONTINUEHERE) ? "-Continue":"");
6852 show_screen_error(buf,i++,vc(15));
6853 continuescreen = ((Map.CurrScr()->flags6&fCONTINUEHERE)!=0);
6854 savecombo = true;
6855 }
6856 else if(Map.CurrScr()->flags6&fCONTINUEHERE)
6857 {
6858 sprintf(buf,"Continue Screen");
6859 show_screen_error(buf,i++,vc(15));
6860 continuescreen = true;
6861 }
6862
6863 if(isSideViewGravity())
6864 {
6865 sprintf(buf,"Sideview Gravity");
6866 show_screen_error(buf,i++,vc(15));
6867 }
6868
6869 if(Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM))
6870 {
6871 sprintf(buf,"Treat As %s%s Screen", (Map.CurrScr()->flags6&fCAVEROOM) ? "Interior":"NES Dungeon",
6872 (Map.CurrScr()->flags6 & (fCAVEROOM|fDUNGEONROOM)) == (fCAVEROOM|fDUNGEONROOM) ? " or NES Dungeon":"");
6873 show_screen_error(buf,i++,vc(15));
6874 }
6875
6876 if(Map.CurrScr()->oceansfx != 0)
6877 {
6878 sprintf(buf,"Ambient Sound: %s",sfx_string[Map.CurrScr()->oceansfx]);
6879 show_screen_error(buf,i++,vc(15));
6880 }
6881
6882 if(Map.CurrScr()->bosssfx != 0)
6883 {
6884 sprintf(buf,"Boss Roar Sound: %s",sfx_string[Map.CurrScr()->bosssfx]);
6885 show_screen_error(buf,i++,vc(15));
6886 }
6887
6888 if(Map.CurrScr()->str)
6889 {
6890 strncpy(buf,MsgString(Map.CurrScr()->str, true, false),72);
6891 buf[72] = '\0';
6892 char shortbuf[72];
6893 strip_extra_spaces(buf);
6894 shorten_string(shortbuf, buf, get_zc_font(font_lfont_l), 72, 280);
6895 sprintf(buf,"String %s",shortbuf);
6896 show_screen_error(buf,i++,vc(15));
6897 }
6898
6899 if((Map.CurrScr()->flags&fWHISTLE) || (Map.CurrScr()->flags7&fWHISTLEWATER))
6900 {
6901 sprintf(buf,"Whistle ->%s%s%s",(Map.CurrScr()->flags&fWHISTLE)?" Stairs":"",
6902 (Map.CurrScr()->flags&fWHISTLE && Map.CurrScr()->flags7&fWHISTLEWATER)?", ":"",
6903 (Map.CurrScr()->flags7&fWHISTLEWATER)?"Dry Lake":"");
6904 show_screen_error(buf,i++,vc(15));
6905 }
6906
6907 switch(Map.CurrScr()->room)
6908 {
6909 case rSP_ITEM:
6910 sprintf(buf,"Special Item is %s",item_string[Map.CurrScr()->catchall]);
6911 show_screen_error(buf,i++, vc(15));
6912 break;
6913
6914 case rINFO:
6915 {
6916 int32_t shop = Map.CurrScr()->catchall;
6917 sprintf(buf,"Pay For Info: -%d, -%d, -%d",
6918 QMisc.info[shop].price[0],QMisc.info[shop].price[1],QMisc.info[shop].price[2]);
6919 show_screen_error(buf,i++, vc(15));
6920 }
6921 break;
6922
6923 case rMONEY:
6924 sprintf(buf,"Secret Money: %d Rupees",Map.CurrScr()->catchall);
6925 show_screen_error(buf,i++, vc(15));
6926 break;
6927
6928 case rGAMBLE:
6929 show_screen_error("Gamble Room",i++, vc(15));
6930 break;
6931
6932 case rREPAIR:
6933 sprintf(buf,"Door Repair: -%d Rupees",Map.CurrScr()->catchall);
6934 show_screen_error(buf,i++, vc(15));
6935 break;
6936
6937 case rRP_HC:
6938 sprintf(buf,"Take %s or %s", item_string[iRPotion], item_string[iHeartC]);
6939 show_screen_error(buf,i++, vc(15));
6940 break;
6941
6942 case rGRUMBLE:
6943 show_screen_error("Feed the Goriya",i++, vc(15));
6944 break;
6945
6946 case rTRIFORCE:
6947 show_screen_error("Triforce Check",i++, vc(15));
6948 break;
6949
6950 case rP_SHOP:
6951 case rSHOP:
6952 {
6953 int32_t shop = Map.CurrScr()->catchall;
6954 sprintf(buf,"%sShop: ",
6955 Map.CurrScr()->room==rP_SHOP ? "Potion ":"");
6956
6957 for(int32_t j=0; j<3; j++) if(QMisc.shop[shop].item[j]>0) // Print the 3 items and prices
6958 {
6959 strcat(buf,item_string[QMisc.shop[shop].item[j]]);
6960 strcat(buf,":");
6961 char pricebuf[8];
6962 sprintf(pricebuf,"%d",QMisc.shop[shop].price[j]);
6963 strcat(buf,pricebuf);
6964
6965 if(j<2 && QMisc.shop[shop].item[j+1]>0) strcat(buf,", ");
6966 }
6967
6968 show_screen_error(buf,i++, vc(15));
6969 }
6970 break;
6971
6972 case rBOTTLESHOP:
6973 {
6974 int32_t shop = Map.CurrScr()->catchall;
6975 sprintf(buf,"Bottle Shop: ");
6976
6977 for(int32_t j=0; j<3; j++) if(QMisc.bottle_shop_types[shop].fill[j]>0) // Print the 3 fills and prices
6978 {
6979 strcat(buf,QMisc.bottle_types[QMisc.bottle_shop_types[shop].fill[j]-1].name);
6980 strcat(buf,":");
6981 char pricebuf[8];
6982 sprintf(pricebuf,"%d",QMisc.bottle_shop_types[shop].price[j]);
6983 strcat(buf,pricebuf);
6984
6985 if(j<2 && QMisc.bottle_shop_types[shop].fill[j+1]>0) strcat(buf,", ");
6986 }
6987
6988 show_screen_error(buf,i++, vc(15));
6989 }
6990 break;
6991
6992 case rTAKEONE:
6993 {
6994 int32_t shop = Map.CurrScr()->catchall;
6995 sprintf(buf,"Take Only One: %s%s%s%s%s",
6996 QMisc.shop[shop].item[0]<1?"":item_string[QMisc.shop[shop].item[0]],QMisc.shop[shop].item[0]>0?", ":"",
6997 QMisc.shop[shop].item[1]<1?"":item_string[QMisc.shop[shop].item[1]],(QMisc.shop[shop].item[1]>0&&QMisc.shop[shop].item[2]>0)?", ":"",
6998 QMisc.shop[shop].item[2]<1?"":item_string[QMisc.shop[shop].item[2]]);
6999 show_screen_error(buf,i++, vc(15));
7000 }
7001 break;
7002
7003 case rBOMBS:
7004 sprintf(buf,"More Bombs: -%d Rupees",Map.CurrScr()->catchall);
7005 show_screen_error(buf,i++, vc(15));
7006 break;
7007
7008 case rARROWS:
7009 sprintf(buf,"More Arrows: -%d Rupees",Map.CurrScr()->catchall);
7010 show_screen_error(buf,i++, vc(15));
7011 break;
7012
7013 case rSWINDLE:
7014 sprintf(buf,"Leave Life or %d Rupees",Map.CurrScr()->catchall);
7015 show_screen_error(buf,i++, vc(15));
7016 break;
7017
7018 case r10RUPIES:
7019 show_screen_error("10 Rupees",i++, vc(15));
7020 break;
7021
7022 case rGANON:
7023 show_screen_error("Ganon Room",i++, vc(15));
7024 break;
7025
7026 case rZELDA:
7027 show_screen_error("Zelda Room",i++, vc(15));
7028 break;
7029
7030 case rMUPGRADE:
7031 show_screen_error("1/2 Magic Upgrade",i++, vc(15));
7032 break;
7033
7034 case rLEARNSLASH:
7035 show_screen_error("Learn Slash",i++, vc(15));
7036 break;
7037
7038 case rWARP:
7039 sprintf(buf,"3-Stair Warp: Warp Ring %d",Map.CurrScr()->catchall);
7040 show_screen_error(buf,i++, vc(15));
7041 break;
7042 }
7043
7044 bool undercombo = false, warpa = false, warpb = false, warpc = false, warpd = false, warpr = false;
7045
7046 word num_ffcs = Map.CurrScr()->numFFC();
7047 for(int32_t c=0; c<176+128+1+num_ffcs; ++c)
7048 {
7049 // Checks both combos, secret combos, undercombos and FFCs
7050 //Fixme:
7051 int32_t ctype =
7052 combobuf[vbound(
7053 (c>=305 ? Map.CurrScr()->ffcs[c-305].data :
7054 c>=304 ? Map.CurrScr()->undercombo :
7055 c>=176 ? Map.CurrScr()->secretcombo[c-176] :
7056 !Map.CurrScr()->valid ? 0 : // Sanity check: does room combo data exist?
7057 Map.CurrScr()->data[c]
7058 ), 0, MAXCOMBOS-1)].type;
7059
7060 if(!undercombo && integrityBoolUnderCombo(Map.CurrScr(),ctype))
7061 {
7062 undercombo = true;
7063 show_screen_error("Under Combo is combo 0",i++, vc(7));
7064 }
7065
7066 // Tile Warp types
7067 switch(ctype)
7068 {
7069 case cSAVE:
7070 case cSAVE2:
7071 if(!savecombo)
7072 {
7073 savecombo = true;
7074
7075 if(integrityBoolSaveCombo(Map.CurrScr(),ctype))
7076 show_screen_error("Save Screen",i++, vc(15));
7077 else
7078 show_screen_error("Save-Continue Screen",i++, vc(15));
7079 }
7080
7081 break;
7082
7083 case cSTAIRR:
7084 case cPITR:
7085 case cSWARPR:
7086 if(!warpr && (Map.CurrScr()->tilewarptype[0]==wtCAVE || Map.CurrScr()->tilewarptype[1]==wtCAVE ||
7087 Map.CurrScr()->tilewarptype[2]==wtCAVE || Map.CurrScr()->tilewarptype[3]==wtCAVE))
7088 {
7089 warpr = true;
7090 show_screen_error("Random Tile Warp contains Cave/Item Cellar",i++, vc(7));
7091 }
7092
7093 break;
7094
7095 case cCAVED:
7096 case cPITD:
7097 case cSTAIRD:
7098 case cCAVE2D:
7099 case cSWIMWARPD:
7100 case cDIVEWARPD:
7101 case cSWARPD:
7102 if(!warpd)
7103 {
7104 warpd = true;
7105 tile_warp_notification(3,buf);
7106 show_screen_error(buf,i++, vc(15));
7107 }
7108
7109 break;
7110
7111 case cCAVEC:
7112 case cPITC:
7113 case cSTAIRC:
7114 case cCAVE2C:
7115 case cSWIMWARPC:
7116 case cDIVEWARPC:
7117 case cSWARPC:
7118 if(!warpc)
7119 {
7120 warpc = true;
7121 tile_warp_notification(2,buf);
7122 show_screen_error(buf,i++, vc(15));
7123 }
7124
7125 break;
7126
7127 case cCAVEB:
7128 case cPITB:
7129 case cSTAIRB:
7130 case cCAVE2B:
7131 case cSWIMWARPB:
7132 case cDIVEWARPB:
7133 case cSWARPB:
7134 if(!warpb)
7135 {
7136 warpb = true;
7137 tile_warp_notification(1,buf);
7138 show_screen_error(buf,i++, vc(15));
7139 }
7140
7141 break;
7142
7143 case cCAVE:
7144 case cPIT:
7145 case cSTAIR:
7146 case cCAVE2:
7147 case cSWIMWARP:
7148 case cDIVEWARP:
7149 case cSWARPA:
7150 if(!warpa)
7151 {
7152 warpa = true;
7153 tile_warp_notification(0,buf);
7154 show_screen_error(buf,i++, vc(15));
7155 }
7156
7157 break;
7158 }
7159 }
7160
7161 int32_t sidewarpnotify = 0;
7162
7163 if(Map.CurrScr()->flags2&wfUP)
7164 {
7165 side_warp_notification(Map.CurrScr()->sidewarpindex&3,0,buf);
7166 show_screen_error(buf,i++, vc(15));
7167 sidewarpnotify|=(1<<(Map.CurrScr()->sidewarpindex&3));
7168 }
7169
7170 if(Map.CurrScr()->flags2&wfDOWN)
7171 {
7172 side_warp_notification((Map.CurrScr()->sidewarpindex>>2)&3,1,buf);
7173 show_screen_error(buf,i++, vc(15));
7174 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>2)&3));
7175 }
7176
7177 if(Map.CurrScr()->flags2&wfLEFT)
7178 {
7179 side_warp_notification((Map.CurrScr()->sidewarpindex>>4)&3,2,buf);
7180 show_screen_error(buf,i++, vc(15));
7181 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>4)&3));
7182 }
7183
7184 if(Map.CurrScr()->flags2&wfRIGHT)
7185 {
7186 side_warp_notification((Map.CurrScr()->sidewarpindex>>6)&3,3,buf);
7187 show_screen_error(buf,i++, vc(15));
7188 sidewarpnotify|=(1<<((Map.CurrScr()->sidewarpindex>>6)&3));
7189 }
7190
7191 if(!(sidewarpnotify&1) && Map.CurrScr()->timedwarptics)
7192 {
7193 side_warp_notification(0,4,buf); // Timed Warp
7194 show_screen_error(buf,i++, vc(15));
7195 }
7196
7197 // Now for errors
7198 if((Map.CurrScr()->flags4&fSAVEROOM) && !savecombo) show_screen_error("Save Point->Continue Here, but no Save Point combo?",i++, vc(14));
7199
7200 if(integrityBoolEnemiesItem(Map.CurrScr())) show_screen_error("Enemies->Item, but no enemies",i++, vc(7));
7201
7202 if(integrityBoolEnemiesSecret(Map.CurrScr())) show_screen_error("Enemies->Secret, but no enemies",i++, vc(7));
7203
7204 if(integrityBoolGuyNoString(Map.CurrScr())) show_screen_error("Non-Fairy Guy, but String is (none)",i++, vc(14));
7205
7206 if(integrityBoolRoomNoGuy(Map.CurrScr())) show_screen_error("Guy is (none)",i++, vc(14));
7207
7208 if(integrityBoolRoomNoString(Map.CurrScr())) show_screen_error("String is (none)",i++, vc(14));
7209
7210 if(integrityBoolRoomNoGuyNoString(Map.CurrScr())) show_screen_error("Guy and String are (none)",i++, vc(14));
7211 }
7212
7213 if(zoom_delay)
7214 draw_screenunit(rSCRMAP,flags);
7215
7216
7217 if(flags&rCLEAR)
7218 {
7219 //Draw the whole gui
7220 blit(menu1,screen,0,0,0,0,zq_screen_w,zq_screen_h);
7221 }
7222 else
7223 {
7224 blit(menu1,screen,0,16,0,16,zq_screen_w,zq_screen_h-16);
7225 blit(menu1,screen,combolist_window.x-64,0,combolist_window.x-64,0,combolist_window.w+64,16);
7226
7227 if(flags&rCOMBO)
7228 blit(menu1,screen,combo_preview.x,combo_preview.y,combo_preview.x,combo_preview.y,combo_preview.w,combo_preview.h);
7229 }
7230
7231 if(earlyret)
7232 return;
7233
7234 //Draw the Main Menu
7235 rectfill(screen,mainbar.x,mainbar.y,mainbar.x+mainbar.w-1,mainbar.y+mainbar.h-1,jwin_pal[jcBOX]);
7236 jwin_draw_frame(screen,mainbar.x,mainbar.y,mainbar.w,mainbar.h,FR_WIN);
7237
7238 FONT* oldfont = font;
7239 font = get_custom_font(CFONT_GUI);
7240
7241 //Drawmode button
7242 draw_text_button(screen,drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode],vc(1),vc(14),0,true);
7243 //Compact button
7244 draw_text_button(screen,compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact", vc(1),vc(14),0,true);
7245 //Zoom buttons
7246 zoom_in_btn_disabled = num_screens_to_draw == 1;
7247 zoom_out_btn_disabled = num_screens_to_draw == mapscreen_num_screens_to_draw_max;
7248 draw_text_button(screen,zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+", vc(1),vc(14),zoom_in_btn_disabled ? D_DISABLED : 0,true);
7249 draw_text_button(screen,zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-", vc(1),vc(14),zoom_out_btn_disabled ? D_DISABLED : 0,true);
7250
7251 font = oldfont;
7252
7253 d_nbmenu_proc(MSG_DRAW, &dialogs[0], 0);
7254
7255 ComboBrushPause=0;
7256
7257 SCRFIX();
7258 if(update)
7259 custom_vsync();
7260 is_refreshing = refreshing = false;
7261 10 }
7262
7263 9 static int minimap_tooltip_id = ttip_register_id();
7264
7265 void select_scr()
7266 {
7267 if(Map.getCurrMap()>=Map.getMapCount())
7268 return;
7269
7270 int32_t tempcb=ComboBrush;
7271 ComboBrush=0;
7272
7273 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
7274
7275 //scooby
7276 while(gui_mouse_b())
7277 {
7278 int32_t x=gui_mouse_x();
7279 int32_t y=gui_mouse_y();
7280
7281 int32_t ind = real_mini.rectind(x,y);
7282
7283 if(ind>=MAPSCRS)
7284 ind-=16;
7285
7286 if(ind > -1 && ind != Map.getCurrScr())
7287 {
7288 Map.setCurrScr(ind);
7289 }
7290
7291 custom_vsync();
7292 refresh(rALL);
7293 }
7294
7295 ComboBrush=tempcb;
7296 }
7297
7298 void clear_cpool()
7299 {
7300 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
7301 {
7302 pool_combos[i].clear();
7303 }
7304 pool_dirty = true;
7305 }
7306
7307 bool select_favorite()
7308 {
7309 int32_t tempcb=ComboBrush;
7310 ComboBrush=0;
7311 bool valid=false;
7312
7313 while(gui_mouse_b())
7314 {
7315 valid=false;
7316 int32_t x=gui_mouse_x();
7317
7318 if(x<favorites_list.x)
7319 x=favorites_list.x;
7320
7321 if(x>favorites_list.x+(favorites_list.w*favorites_list.xscale)-1)
7322 x=favorites_list.x+(favorites_list.w*favorites_list.xscale)-1;
7323
7324 int32_t y=gui_mouse_y();
7325
7326 if(y<favorites_list.y)
7327 y=favorites_list.y;
7328
7329 if(y>favorites_list.y+(favorites_list.h*favorites_list.yscale)-1)
7330 y=favorites_list.y+(favorites_list.h*favorites_list.yscale)-1;
7331
7332 int32_t tempc=(((y-favorites_list.y)/favorites_list.yscale)*FAVORITECOMBO_PER_ROW)+((x-favorites_list.x)/favorites_list.xscale) + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
7333
7334 if(tempc >= MAXFAVORITECOMBOS)
7335 {
7336 //Nothing, invalid
7337 }
7338 else
7339 {
7340 if(favorite_combos[tempc]!=-1)
7341 {
7342 switch(favorite_combo_modes[tempc])
7343 {
7344 case dm_alias:
7345 draw_mode = dm_alias;
7346 combo_apos = favorite_combos[tempc];
7347 break;
7348 case dm_cpool:
7349 draw_mode = dm_cpool;
7350 combo_pool_pos = favorite_combos[tempc];
7351 break;
7352 case dm_auto:
7353 draw_mode = dm_auto;
7354 combo_auto_pos = favorite_combos[tempc];
7355 break;
7356 default:
7357 draw_mode = dm_normal;
7358 Combo = favorite_combos[tempc];
7359 }
7360 if(AutoBrush)
7361 BrushWidth = BrushHeight = 1;
7362 valid=true;
7363 fix_drawing_mode_menu();
7364 }
7365 }
7366
7367 custom_vsync();
7368 refresh(rALL);
7369 }
7370
7371 ComboBrush=tempcb;
7372 return valid;
7373 }
7374
7375 void select_combo(int32_t clist)
7376 {
7377 current_combolist=clist;
7378 int32_t tempcb=ComboBrush;
7379 ComboBrush=0;
7380
7381 int autobrush_cx = -1, autobrush_cy = -1;
7382 int autobrush_first = First[current_combolist];
7383 auto& curlist = combolist[current_combolist];
7384 AutoBrushRevert = (key[KEY_ALT]||key[KEY_ALTGR]);
7385 while(gui_mouse_b())
7386 {
7387 int32_t x=gui_mouse_x();
7388
7389 if(x<curlist.x)
7390 x=curlist.x;
7391
7392 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7393 x=curlist.x+(curlist.w*curlist.xscale)-1;
7394
7395 int32_t y=gui_mouse_y();
7396
7397 if(y<curlist.y)
7398 y=curlist.y;
7399
7400 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7401 y=curlist.y+(curlist.h*curlist.yscale)-1;
7402
7403 int cx = ((x-curlist.x)/curlist.xscale), cy = ((y-curlist.y)/curlist.yscale);
7404 if(AutoBrush)
7405 {
7406 if(autobrush_cx < 0)
7407 {
7408 autobrush_cx = cx;
7409 autobrush_cy = cy;
7410 }
7411 BrushWidth = vbound(abs(autobrush_cx-cx)+1,1,16);
7412 BrushHeight = vbound(abs(autobrush_cy-cy)+1,1,11);
7413 cx = std::min(autobrush_cx,cx);
7414 cy = std::min(autobrush_cy,cy);
7415 }
7416 Combo=(cy*curlist.w)+cx+First[current_combolist];
7417 custom_vsync();
7418 refresh(rALL);
7419 if(AutoBrush) //Prevent any scrolling
7420 First[current_combolist] = autobrush_first;
7421 }
7422 if(key[KEY_ALT]||key[KEY_ALTGR])
7423 AutoBrushRevert = true;
7424 position_mouse_z(0);
7425 ComboBrush=tempcb;
7426 }
7427
7428 void select_comboa(int32_t clist)
7429 {
7430 current_comboalist=clist;
7431 int32_t tempcb=ComboBrush;
7432 ComboBrush=0;
7433 alias_cset_mod=0;
7434
7435 auto& curlist = comboaliaslist[current_comboalist];
7436 while(gui_mouse_b())
7437 {
7438 int32_t x=gui_mouse_x();
7439
7440 if(x<curlist.x)
7441 x=curlist.x;
7442
7443 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7444 x=curlist.x+(curlist.w*curlist.xscale)-1;
7445
7446 int32_t y=gui_mouse_y();
7447
7448 if(y<curlist.y)
7449 y=curlist.y;
7450
7451 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7452 y=curlist.y+(curlist.h*curlist.yscale)-1;
7453
7454 combo_apos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_alistpos[current_comboalist];
7455 custom_vsync();
7456 refresh(rALL);
7457 }
7458
7459 ComboBrush=tempcb;
7460 }
7461
7462 void select_combop(int32_t clist)
7463 {
7464 current_cpoollist=clist;
7465 int32_t tempcb=ComboBrush;
7466 ComboBrush=0;
7467
7468 auto& curlist = comboaliaslist[current_cpoollist];
7469 while(gui_mouse_b())
7470 {
7471 int32_t x=gui_mouse_x();
7472
7473 if(x<curlist.x) x=curlist.x;
7474
7475 if(x>curlist.x+(curlist.w*curlist.xscale)-1)
7476 x=curlist.x+(curlist.w*curlist.xscale)-1;
7477
7478 int32_t y=gui_mouse_y();
7479
7480 if(y<curlist.y) y=curlist.y;
7481
7482 if(y>curlist.y+(curlist.h*curlist.yscale)-1)
7483 y=curlist.y+(curlist.h*curlist.yscale)-1;
7484
7485 combo_pool_pos=(((y-curlist.y)/curlist.yscale)*curlist.w)+((x-curlist.x)/curlist.xscale)+combo_pool_listpos[current_cpoollist];
7486 custom_vsync();
7487 refresh(rALL);
7488 }
7489
7490 ComboBrush=tempcb;
7491 }
7492
7493 void select_autocombo(int32_t clist)
7494 {
7495 current_cautolist = clist;
7496 int32_t tempcb = ComboBrush;
7497 ComboBrush = 0;
7498
7499 auto& curlist = comboaliaslist[current_cautolist];
7500 while (gui_mouse_b())
7501 {
7502 int32_t x = gui_mouse_x();
7503
7504 if (x < curlist.x) x = curlist.x;
7505
7506 if (x > curlist.x + (curlist.w * curlist.xscale) - 1)
7507 x = curlist.x + (curlist.w * curlist.xscale) - 1;
7508
7509 int32_t y = gui_mouse_y();
7510
7511 if (y < curlist.y) y = curlist.y;
7512
7513 if (y > curlist.y + (curlist.h * curlist.yscale) - 1)
7514 y = curlist.y + (curlist.h * curlist.yscale) - 1;
7515
7516 combo_auto_pos = (((y - curlist.y) / curlist.yscale) * curlist.w) + ((x - curlist.x) / curlist.xscale) + combo_auto_listpos[current_cautolist];
7517 cauto_height = combo_autos[combo_auto_pos].getArg() + 1;
7518 custom_vsync();
7519 refresh(rALL);
7520 }
7521
7522 ComboBrush = tempcb;
7523 }
7524
7525 void update_combobrush()
7526 {
7527 clear_bitmap(brushbmp);
7528
7529 if(draw_mode==dm_alias)
7530 {
7531 //int32_t count=(combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*(comboa_lmasktotal(combo_aliases[combo_apos].layermask));
7532 for(int32_t z=0; z<=comboa_lmasktotal(combo_aliases[combo_apos].layermask); z++)
7533 {
7534 for(int32_t y=0; y<=combo_aliases[combo_apos].height; y++)
7535 {
7536 for(int32_t x=0; x<=combo_aliases[combo_apos].width; x++)
7537 {
7538 int32_t position = ((y*(combo_aliases[combo_apos].width+1))+x)+((combo_aliases[combo_apos].width+1)*(combo_aliases[combo_apos].height+1)*z);
7539
7540 if(combo_aliases[combo_apos].combos[position])
7541 {
7542 if(z==0)
7543 {
7544 putcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7545 }
7546 else
7547 {
7548 overcombo(brushbmp,x<<4,y<<4,combo_aliases[combo_apos].combos[position],wrap(combo_aliases[combo_apos].csets[position]+alias_cset_mod, 0, 13));
7549 }
7550 }
7551 }
7552 }
7553 }
7554
7555 int xoff = 6, yoff = 6;
7556 if(FloatBrush) // Offset the floating pixels, so the 'x' appears centered on the combo still -Em
7557 {
7558 xoff += 2;
7559 yoff += 2;
7560 }
7561 if(alias_origin & 1) // Right-align
7562 xoff += combo_aliases[combo_apos].width*16;
7563 if(alias_origin & 2) // Bottom-align
7564 yoff += combo_aliases[combo_apos].height*16;
7565
7566 textprintf_shadowed_ex(brushbmp, get_zc_font(font_sfont), xoff, yoff, vc(15), vc(0), -1, "x");
7567 }
7568 else if(draw_mode != dm_cpool)
7569 {
7570 int32_t cid = combobrushoverride > -1 ? combobrushoverride : Combo;
7571 int32_t c = 0;
7572
7573 for(int32_t i=0; i<256; i++)
7574 {
7575 if(unsigned(cid+c) >= MAXCOMBOS) break;
7576 if(((i%COMBOS_PER_ROW)<BrushWidth)&&((i/COMBOS_PER_ROW)<BrushHeight))
7577 {
7578 put_combo(brushbmp,(i%COMBOS_PER_ROW)<<4,(i/COMBOS_PER_ROW)<<4,cid+c,CSet,Flags&(cFLAGS|cWALK),0);
7579 }
7580
7581 if(((cid+c)&3)==3)
7582 c+=48;
7583
7584 ++c;
7585
7586 if((i%COMBOS_PER_ROW)==(COMBOS_PER_ROW-1))
7587 c-=256;
7588 }
7589 }
7590 }
7591
7592 byte relational_source_grid[256]=
7593 {
7594 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
7595 16, 16, 17, 17, 18, 18, 19, 19, 16, 16, 17, 17, 18, 18, 19, 19,
7596 20, 20, 20, 20, 21, 21, 21, 21, 22, 22, 22, 22, 23, 23, 23, 23,
7597 24, 24, 24, 24, 25, 25, 25, 25, 24, 24, 24, 24, 25, 25, 25, 25,
7598 26, 27, 26, 27, 26, 27, 26, 27, 28, 29, 28, 29, 28, 29, 28, 29,
7599 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
7600 31, 31, 31, 31, 31, 31, 31, 31, 32, 32, 32, 32, 32, 32, 32, 32,
7601 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33, 33,
7602 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37, 34, 35, 36, 37,
7603 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39, 38, 38, 39, 39,
7604 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40, 40,
7605 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41, 41,
7606 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43, 42, 43,
7607 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 44,
7608 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45, 45,
7609 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46, 46
7610 };
7611
7612 static void draw_autocombo(ComboPosition combo_pos, bool rclick, bool pressframe = false)
7613 {
7614 combo_auto &ca = combo_autos[combo_auto_pos];
7615 int scr = Map.getScreenForPosition(combo_pos);
7616 int pos = combo_pos.truncate();
7617
7618 if (ca.valid())
7619 {
7620 switch (ca.getType())
7621 {
7622 case AUTOCOMBO_BASIC:
7623 {
7624 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7625 if (rclick)
7626 ap.erase(scr, pos);
7627 else
7628 ap.execute(scr, pos);
7629 break;
7630 }
7631 case AUTOCOMBO_Z1:
7632 {
7633 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7634 if (rclick)
7635 ap.erase(scr, pos);
7636 else
7637 ap.execute(scr, pos);
7638 break;
7639 }
7640 case AUTOCOMBO_FENCE:
7641 {
7642 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7643 if (rclick)
7644 ap.erase(scr, pos);
7645 else
7646 ap.execute(scr, pos);
7647 break;
7648 }
7649 case AUTOCOMBO_Z4:
7650 {
7651 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, scr, pos, &ca, cauto_height);
7652 if (rclick)
7653 ap.erase(scr, pos);
7654 else
7655 ap.execute(scr, pos);
7656 break;
7657 }
7658 case AUTOCOMBO_RELATIONAL:
7659 {
7660 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7661 if (rclick)
7662 ap.erase(scr, pos);
7663 else
7664 ap.execute(scr, pos);
7665 break;
7666 }
7667 case AUTOCOMBO_DGNCARVE:
7668 {
7669 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7670 if (rclick)
7671 ap.erase(scr, pos);
7672 else
7673 ap.execute(scr, pos);
7674 break;
7675 }
7676 case AUTOCOMBO_DOR:
7677 {
7678 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, scr, pos, &ca, cauto_height);
7679 if (rclick)
7680 ap.erase(scr, pos);
7681 else
7682 ap.execute(scr, pos);
7683 break;
7684 }
7685 case AUTOCOMBO_TILING:
7686 {
7687 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7688 {
7689 int32_t x = (scr % 16) * 16 + (pos % 16);
7690 int32_t y = (scr / 16) * 11 + (pos / 16);
7691 byte w = (ca.getArg() & 0xF) + 1;
7692 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7693 ca.setOffsets(x % w, y % h);
7694 }
7695 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7696 if (rclick)
7697 ap.erase(scr, pos);
7698 else
7699 ap.execute(scr, pos);
7700 break;
7701 }
7702 case AUTOCOMBO_REPLACE:
7703 {
7704 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7705 if (rclick)
7706 ap.erase(scr, pos);
7707 else
7708 ap.execute(scr, pos);
7709 break;
7710 }
7711 case AUTOCOMBO_DENSEFOREST:
7712 {
7713 if (pressframe && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7714 {
7715 int32_t x = (scr % 16) * 16 + (pos % 16);
7716 int32_t y = (scr / 16) * 11 + (pos / 16);
7717 ca.setOffsets(x % 2, y % 2);
7718 }
7719 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7720 if (rclick)
7721 ap.erase(scr, pos);
7722 else
7723 ap.execute(scr, pos);
7724 break;
7725 }
7726 case AUTOCOMBO_EXTEND:
7727 {
7728 if (CHECK_CTRL_CMD)
7729 break;
7730 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7731 if (rclick)
7732 ap.erase(scr, pos);
7733 else
7734 ap.execute(scr, pos);
7735 break;
7736 }
7737 }
7738 }
7739 else
7740 {
7741 ca.updateValid();
7742 if(!ca.valid())
7743 InfoDialog("Notice", "The autocombo you're trying to use is invalid. Reason:"
7744 + ca.getInvalidReason()).show();
7745 }
7746 }
7747
7748 static void draw_autocombo_command(ComboPosition combo_pos, int32_t cmd = 0, int32_t arg = 0)
7749 {
7750 combo_auto ca = combo_autos[combo_auto_pos];
7751 int scr = Map.getScreenForPosition(combo_pos);
7752 int pos = combo_pos.truncate();
7753
7754 if (ca.valid())
7755 {
7756 switch (ca.getType())
7757 {
7758 case AUTOCOMBO_FENCE:
7759 {
7760 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7761 ap.flip_all_connected(scr, pos, 2048);
7762 break;
7763 }
7764 case AUTOCOMBO_Z4:
7765 {
7766 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, scr, pos, &ca, cauto_height);
7767 switch (cmd)
7768 {
7769 case 0: // Flip
7770 ap.flip_all_connected(scr, pos, 2048);
7771 break;
7772 case 1: // Grow
7773 ap.resize_connected(scr, pos, 2048, vbound(arg, 1, 9));
7774 break;
7775 }
7776 }
7777 }
7778 }
7779 }
7780
7781 static int32_t get_autocombo_floating_cid(ComboPosition combo_pos, bool clicked)
7782 {
7783 combo_auto& ca = combo_autos[combo_auto_pos];
7784 int scr = Map.getScreenForPosition(combo_pos);
7785 int pos = combo_pos.truncate();
7786 int cid = 0;
7787
7788 if (ca.valid() && Map.isValidPosition(mouse_combo_pos))
7789 {
7790 switch (ca.getType())
7791 {
7792 case AUTOCOMBO_BASIC:
7793 {
7794 AutoPattern::autopattern_basic ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7795 cid = ap.get_floating_cid(scr, pos);
7796 break;
7797 }
7798
7799 case AUTOCOMBO_Z1:
7800 {
7801 AutoPattern::autopattern_flatmtn ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7802 cid = ap.get_floating_cid(scr, pos);
7803 break;
7804 }
7805 case AUTOCOMBO_FENCE:
7806 {
7807 AutoPattern::autopattern_fence ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7808 cid = ap.get_floating_cid(scr, pos);
7809 break;
7810 }
7811 case AUTOCOMBO_Z4:
7812 {
7813 AutoPattern::autopattern_cakemtn ap(ca.getType(), CurrentLayer, scr, pos, &ca, cauto_height);
7814 cid = ap.get_floating_cid(scr, pos);
7815 break;
7816 }
7817 case AUTOCOMBO_RELATIONAL:
7818 {
7819 AutoPattern::autopattern_relational ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7820 cid = ap.get_floating_cid(scr, pos);
7821 break;
7822 }
7823 case AUTOCOMBO_DGNCARVE:
7824 {
7825 AutoPattern::autopattern_dungeoncarve ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7826 cid = ap.get_floating_cid(scr, pos);
7827 break;
7828 }
7829 case AUTOCOMBO_DOR:
7830 {
7831 AutoPattern::autopattern_dormtn ap(ca.getType(), CurrentLayer, scr, pos, &ca, cauto_height);
7832 cid = ap.get_floating_cid(scr, pos);
7833 break;
7834 }
7835 case AUTOCOMBO_TILING:
7836 {
7837 std::pair<byte, byte> offs = ca.getOffsets();
7838 if (!clicked && (key[KEY_LSHIFT] || key[KEY_RSHIFT]))
7839 {
7840 int32_t x = (scr % 16) * 16 + (pos % 16);
7841 int32_t y = (scr / 16) * 11 + (pos / 16);
7842 byte w = (ca.getArg() & 0xF) + 1;
7843 byte h = ((ca.getArg() >> 4) & 0xF) + 1;
7844 offs.first = (x % w);
7845 offs.second = (y % h);
7846 }
7847 AutoPattern::autopattern_tiling ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7848 cid = ap.get_floating_cid(scr, pos);
7849 break;
7850 }
7851 case AUTOCOMBO_REPLACE:
7852 {
7853 AutoPattern::autopattern_replace ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7854 cid = ap.get_floating_cid(scr, pos);
7855 break;
7856 }
7857 case AUTOCOMBO_DENSEFOREST:
7858 {
7859 AutoPattern::autopattern_denseforest ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7860 cid = ap.get_floating_cid(scr, pos);
7861 break;
7862 }
7863 case AUTOCOMBO_EXTEND:
7864 {
7865 AutoPattern::autopattern_extend ap(ca.getType(), CurrentLayer, scr, pos, &ca);
7866 cid = ap.get_floating_cid(scr, pos);
7867 break;
7868 }
7869 }
7870 }
7871 return cid;
7872 }
7873
7874 void change_autocombo_height(int32_t change)
7875 {
7876 bool can_change = false;
7877 if (draw_mode == dm_auto)
7878 {
7879 combo_auto ca = combo_autos[combo_auto_pos];
7880 switch (ca.getType())
7881 {
7882 case AUTOCOMBO_Z4:
7883 can_change = true;
7884 [[fallthrough]];
7885 case AUTOCOMBO_DOR:
7886 break;
7887 default:
7888 return;
7889 }
7890 }
7891 else
7892 return;
7893
7894 int32_t x = gui_mouse_x();
7895 int32_t y = gui_mouse_y();
7896 double startx = mapscreen_x + (showedges ? (16 * mapscreen_single_scale) : 0);
7897 double starty = mapscreen_y + (showedges ? (16 * mapscreen_single_scale) : 0);
7898 int32_t startxint = mapscreen_x + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7899 int32_t startyint = mapscreen_y + (showedges ? int32_t(16 * mapscreen_single_scale) : 0);
7900 ComboPosition pos = get_mapscreen_mouse_combo_pos();
7901
7902 if (can_change && isinRect(x, y, startxint, startyint, int32_t(startx + (256 * mapscreen_single_scale) - 1), int32_t(starty + (176 * mapscreen_single_scale) - 1)))
7903 {
7904 Map.StartListCommand();
7905 draw_autocombo_command(pos, 1, cauto_height + change);
7906 Map.FinishListCommand();
7907 }
7908 cauto_height = vbound(cauto_height + change, 1, 9);
7909 }
7910
7911 void draw(bool justcset)
7912 {
7913 combo_pool const& pool = combo_pools[combo_pool_pos];
7914 if(draw_mode == dm_cpool && !pool.valid())
7915 return;
7916 saved=false;
7917
7918 refresh(rMAP+rSCRMAP);
7919 ComboPosition last_pos = {-1, -1};
7920
7921 Map.StartListCommand();
7922 bool pressframe = true;
7923 while(gui_mouse_b())
7924 {
7925 int32_t x=gui_mouse_x();
7926 int32_t y=gui_mouse_y();
7927 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
7928 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
7929 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
7930 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
7931 int num_combos_width = 16 * Map.getViewSize();
7932 int num_combos_height = 11 * Map.getViewSize();
7933
7934 if(isinRect(x,y,startxint,startyint,int32_t(startx+(256*mapscreen_screenunit_scale)-1),int32_t(starty+(176*mapscreen_screenunit_scale)-1)))
7935 {
7936 int32_t cxstart=(x-startx)/(16*mapscreen_single_scale);
7937 int32_t cystart=(y-starty)/(16*mapscreen_single_scale);
7938 ComboPosition combo_start = {cxstart, cystart};
7939 if (pressframe)
7940 {
7941 last_pos = combo_start;
7942 }
7943 else if (combo_start == last_pos)
7944 {
7945 custom_vsync();
7946 refresh(rALL);
7947 continue;
7948 }
7949 else if(draw_mode == dm_auto)
7950 {
7951 // TODO: support when zoomed out.
7952 if (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE || combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4)
7953 {
7954 // Don't allow moving the brush at anything but cardinal directions while in these modes
7955 bool did_diag = std::abs(combo_start.x - last_pos.x) == 1 && std::abs(combo_start.y - last_pos.y) == 1;
7956
7957 if (did_diag)
7958 {
7959 int32_t oldx = last_pos.x;
7960 int32_t oldy = last_pos.y;
7961 int32_t cx = (oldx * 16 * mapscreen_single_scale) + 8;
7962 int32_t cy = (oldy * 16 * mapscreen_single_scale) + 8;
7963 int32_t nx = x - startxint;
7964 int32_t ny = y - startyint;
7965 if (std::abs(nx - cx) < std::abs(ny - cy))
7966 {
7967 oldy = vbound(oldy + ((ny - cy) < 0 ? -1 : 1), 0, 11);
7968 }
7969 else
7970 {
7971 oldx = vbound(oldx + ((nx - cx) < 0 ? -1 : 1), 0, 15);
7972 }
7973 combo_start = {oldx, oldy};
7974 }
7975 }
7976 }
7977 last_pos = combo_start;
7978
7979 switch(draw_mode)
7980 {
7981 case dm_normal:
7982 {
7983 int32_t cc=Combo;
7984
7985 for(int32_t cy=0; cy+cystart<num_combos_height&&cy<BrushHeight; cy++)
7986 {
7987 for(int32_t cx=0; cx+cxstart<num_combos_width&&cx<BrushWidth; cx++)
7988 {
7989 auto pos = combo_start + ComboPosition{cx, cy};
7990 cc=Combo + cx + cy*4;
7991 Map.DoSetComboCommand(pos, justcset ? -1 : cc, CSet);
7992 }
7993 }
7994
7995 update_combobrush();
7996 }
7997 break;
7998 case dm_cpool:
7999 {
8000 int32_t cid = Combo;
8001 int8_t cs = CSet;
8002 pool.pick(cid,cs);
8003 Map.DoSetComboCommand(combo_start, justcset ? -1 : cid, cs);
8004
8005 update_combobrush();
8006 }
8007 break;
8008
8009 case dm_alias:
8010 {
8011 combo_alias *combo = &combo_aliases[combo_apos];
8012 if(!combo->layermask)
8013 {
8014 int32_t ox=0, oy=0;
8015
8016 switch(alias_origin)
8017 {
8018 case 0:
8019 ox=0;
8020 oy=0;
8021 break;
8022
8023 case 1:
8024 ox=(combo->width);
8025 oy=0;
8026 break;
8027
8028 case 2:
8029 ox=0;
8030 oy=(combo->height);
8031 break;
8032
8033 case 3:
8034 ox=(combo->width);
8035 oy=(combo->height);
8036 break;
8037 }
8038
8039 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8040 {
8041 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8042 {
8043 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8044 {
8045 int32_t p=(cy*(combo->width+1))+cx;
8046
8047 if(combo->combos[p])
8048 {
8049 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8050 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8051 }
8052 }
8053 }
8054 }
8055 }
8056 else
8057 {
8058 int32_t laypos = 0;
8059 int32_t ox=0, oy=0;
8060
8061 switch(alias_origin)
8062 {
8063 case 0:
8064 ox=0;
8065 oy=0;
8066 break;
8067
8068 case 1:
8069 ox=(combo->width);
8070 oy=0;
8071 break;
8072
8073 case 2:
8074 ox=0;
8075 oy=(combo->height);
8076 break;
8077
8078 case 3:
8079 ox=(combo->width);
8080 oy=(combo->height);
8081 break;
8082 }
8083
8084 for(int32_t cz=0; cz<7; cz++)
8085 {
8086 if (cz > 0 && !(combo->layermask & (1<<(cz-1))))
8087 continue;
8088
8089 if (cz > 0)
8090 laypos++;
8091
8092 for(int32_t cy=0; cy-oy+cystart<num_combos_height&&cy<=combo->height; cy++)
8093 {
8094 for(int32_t cx=0; cx-ox+cxstart<num_combos_width&&cx<=combo->width; cx++)
8095 {
8096 if((cx+cxstart-ox>=0)&&(cy+cystart-oy>=0))
8097 {
8098 int32_t p=((cy*(combo->width+1))+cx)+((combo->width+1)*(combo->height+1)*laypos);
8099
8100 if (combo->combos[p])
8101 {
8102 auto pos = combo_start + ComboPosition{cx - ox, cy - oy};
8103 if(cz > 0 && Map.Scr(pos)->layermap[cz - 1] == 0)
8104 continue;
8105 int prev = CurrentLayer;
8106 CurrentLayer = cz;
8107 Map.DoSetComboCommand(pos, combo->combos[p], wrap(combo->csets[p]+alias_cset_mod, 0, 13));
8108 CurrentLayer = prev;
8109 }
8110 }
8111 }
8112 }
8113 }
8114 }
8115
8116 break;
8117 }
8118
8119 case dm_auto:
8120 {
8121 draw_autocombo(combo_start, gui_mouse_b() & 2, pressframe);
8122
8123 combobrushoverride = get_autocombo_floating_cid(combo_start, true);
8124 update_combobrush();
8125 }
8126 }
8127 }
8128 pressframe = false;
8129
8130 custom_vsync();
8131 refresh(rALL);
8132 }
8133
8134 Map.FinishListCommand();
8135 if(AutoBrushRevert)
8136 {
8137 AutoBrushRevert = false;
8138 BrushWidth = 1;
8139 BrushHeight = 1;
8140 }
8141 }
8142
8143 static void replace(ComboPosition start)
8144 {
8145 int32_t cid = Combo;
8146 int8_t cs = CSet;
8147 combo_pool const& pool = combo_pools[combo_pool_pos];
8148 if(draw_mode == dm_cpool && !pool.valid())
8149 return;
8150
8151 int c = start.truncate();
8152 mapscr* scr = Map.Scr(start, CurrentLayer);
8153 if (!scr) return;
8154
8155 int num_combos_width = 16 * Map.getViewSize();
8156 int num_combos_height = 11 * Map.getViewSize();
8157 int targetcombo = scr->data[c];
8158 int targetcset = scr->cset[c];
8159
8160 saved = false;
8161 Map.StartListCommand();
8162 if(key[KEY_LSHIFT] || key[KEY_RSHIFT])
8163 {
8164 for (int x = 0; x < num_combos_width; x++)
8165 {
8166 for (int y = 0; y < num_combos_height; y++)
8167 {
8168 ComboPosition pos = {x, y};
8169 int c = pos.truncate();
8170 mapscr* scr = Map.Scr(pos, CurrentLayer);
8171 if (!scr)
8172 continue;
8173
8174 if ((scr->cset[c]) == targetcset)
8175 {
8176 if(draw_mode == dm_cpool)
8177 pool.pick(cid,cs);
8178 Map.DoSetComboCommand(pos, -1, cs);
8179 }
8180 }
8181 }
8182 }
8183 else
8184 {
8185 for (int x = 0; x < num_combos_width; x++)
8186 {
8187 for (int y = 0; y < num_combos_height; y++)
8188 {
8189 ComboPosition pos = {x, y};
8190 int c = pos.truncate();
8191 mapscr* scr = Map.Scr(pos, CurrentLayer);
8192 if (!scr)
8193 continue;
8194
8195 if(((scr->data[c])==targetcombo) &&
8196 ((scr->cset[c])==targetcset))
8197 {
8198 if(draw_mode == dm_cpool)
8199 pool.pick(cid,cs);
8200 Map.DoSetComboCommand(pos, cid, cs);
8201 }
8202 }
8203 }
8204 }
8205 Map.FinishListCommand();
8206
8207 refresh(rMAP);
8208 }
8209
8210 static void draw_block(ComboPosition start, int32_t w, int32_t h)
8211 {
8212 int32_t cid = Combo;
8213 int8_t cs = CSet;
8214 if(draw_mode == dm_cpool)
8215 {
8216 combo_pool const& pool = combo_pools[combo_pool_pos];
8217 if(!pool.pick(cid,cs)) return;
8218 }
8219
8220 mapscr* scr = Map.Scr(start, CurrentLayer);
8221 if (!scr) return;
8222
8223 saved = false;
8224 Map.StartListCommand();
8225 for (int32_t y=0; y < h && y < 11*Map.getViewSize(); y++)
8226 for (int32_t x=0; x < w && x < 16*Map.getViewSize(); x++)
8227 {
8228 Map.DoSetComboCommand(start + ComboPosition{x, y}, cid+(y*4)+x, cs);
8229 }
8230
8231 Map.FinishListCommand();
8232 refresh(rMAP+rSCRMAP);
8233 }
8234
8235 static std::vector<ComboPosition> flood_filler(ComboPosition start_pos, bool allow_diagonal, std::function<bool(ComboPosition)> check)
8236 {
8237 std::vector<ComboPosition> seen, queue;
8238
8239 queue.push_back(start_pos);
8240 while (!queue.empty())
8241 {
8242 ComboPosition pos = queue.back();
8243 queue.pop_back();
8244 seen.push_back(pos);
8245
8246 ComboPosition pos2;
8247 #define FLOOD_FILLER_CHECK(dx, dy)\
8248 pos2 = pos + ComboPosition{dx, dy};\
8249 if (std::find(seen.begin(), seen.end(), pos2) == seen.end() && check(pos2))\
8250 queue.push_back(pos2);
8251
8252 FLOOD_FILLER_CHECK(0, 1);
8253 FLOOD_FILLER_CHECK(0, -1);
8254 FLOOD_FILLER_CHECK(1, 0);
8255 FLOOD_FILLER_CHECK(-1, 0);
8256
8257 if (allow_diagonal)
8258 {
8259 FLOOD_FILLER_CHECK(1, 1);
8260 FLOOD_FILLER_CHECK(1, -1);
8261 FLOOD_FILLER_CHECK(-1, 1);
8262 FLOOD_FILLER_CHECK(-1, -1);
8263 }
8264
8265 #undef FLOOD_FILLER_CHECK
8266 }
8267
8268 return seen;
8269 }
8270
8271 static void fill(int32_t targetcombo, int32_t targetcset, ComboPosition start_pos, bool allow_diagonal, bool only_cset)
8272 {
8273 bool rclick = gui_mouse_b() & 2;
8274 bool ignored_combo = false;
8275
8276 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8277 if (!scr)
8278 return;
8279
8280 int num_combos_width = 16 * Map.getViewSize();
8281 int num_combos_height = 11 * Map.getViewSize();
8282
8283 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8284 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8285 return false;
8286
8287 mapscr* scr = Map.Scr(pos, CurrentLayer);
8288 if (!scr || !scr->is_valid())
8289 return false;
8290
8291 int cid = scr->data[pos.truncate()];
8292 int cset = scr->cset[pos.truncate()];
8293
8294 if (draw_mode == dm_auto)
8295 {
8296 combo_auto const& cauto = combo_autos[combo_auto_pos];
8297
8298 ignored_combo = cauto.isIgnoredCombo(cid);
8299 if (rclick)
8300 {
8301 if (cauto.containsCombo(targetcombo))
8302 {
8303 if (!cauto.containsCombo(cid))
8304 return false;
8305 if (cauto.getType() == AUTOCOMBO_REPLACE && ignored_combo)
8306 return false;
8307 }
8308 else
8309 return false;
8310 }
8311 else
8312 {
8313 if (cid != targetcombo && !ignored_combo)
8314 return false;
8315 if (cauto.getType() == AUTOCOMBO_REPLACE && !ignored_combo)
8316 return false;
8317 }
8318
8319 if (cset != targetcset && !ignored_combo)
8320 return false;
8321 }
8322 else
8323 {
8324 if(!only_cset)
8325 {
8326 if (cid != targetcombo)
8327 return false;
8328 }
8329
8330 if (cset != targetcset)
8331 return false;
8332 }
8333
8334 return true;
8335 });
8336
8337 for (auto& pos : combo_positions)
8338 {
8339 int32_t cid = Combo;
8340 int8_t cs = CSet;
8341
8342 if (draw_mode == dm_cpool)
8343 {
8344 combo_pool const& pool = combo_pools[combo_pool_pos];
8345 if (!pool.pick(cid, cs)) continue;
8346 }
8347 else if (draw_mode == dm_auto)
8348 {
8349 combo_auto const& cauto = combo_autos[combo_auto_pos];
8350 if (!cauto.valid())
8351 continue;
8352 if (!rclick && (cauto.containsCombo(targetcombo) && !ignored_combo))
8353 continue;
8354 if (rclick && cauto.getEraseCombo() == targetcombo)
8355 continue;
8356 }
8357
8358 if (draw_mode == dm_auto)
8359 draw_autocombo(pos, rclick);
8360 else
8361 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8362 }
8363 }
8364
8365 static void fill_flag(int32_t targetflag, ComboPosition start_pos, bool allow_diagonal)
8366 {
8367 mapscr* scr = Map.ScrMakeValid(start_pos, CurrentLayer);
8368 if (!scr)
8369 return;
8370
8371 int num_combos_width = 16 * Map.getViewSize();
8372 int num_combos_height = 11 * Map.getViewSize();
8373
8374 auto combo_positions = flood_filler(start_pos, allow_diagonal, [&](ComboPosition pos){
8375 if (pos.x < 0 || pos.y < 0 || pos.x >= num_combos_width || pos.y >= num_combos_height)
8376 return false;
8377
8378 mapscr* scr = Map.Scr(pos, CurrentLayer);
8379 if (!scr || !scr->is_valid())
8380 return false;
8381
8382 if (scr->sflag[pos.truncate()] != targetflag)
8383 return false;
8384
8385 return true;
8386 });
8387
8388 for (auto& pos : combo_positions)
8389 Map.DoSetFlagCommand(pos, Flag);
8390 }
8391
8392 static void fill2(int32_t targetcombo, int32_t targetcset, ComboPosition pos, int32_t dir, int32_t diagonal, bool only_cset)
8393 {
8394 mapscr* scr = Map.Scr(pos, CurrentLayer);
8395 if (!scr || !scr->is_valid())
8396 return;
8397
8398 int cid = scr->data[pos.truncate()];
8399 int cset = scr->cset[pos.truncate()];
8400
8401 if (!only_cset)
8402 {
8403 if (cid == targetcombo)
8404 return;
8405 }
8406
8407 if (cset == targetcset)
8408 return;
8409
8410 cid = Combo;
8411 int8_t cs = CSet;
8412 if(draw_mode == dm_cpool)
8413 {
8414 combo_pool const& pool = combo_pools[combo_pool_pos];
8415 if(!pool.pick(cid,cs)) return;
8416 }
8417
8418 Map.DoSetComboCommand(pos, only_cset ? -1 : cid, cs);
8419
8420 int num_combos_width = 16 * Map.getViewSize();
8421 int num_combos_height = 11 * Map.getViewSize();
8422
8423 if (pos.y > 0 && dir != down)
8424 fill2(targetcombo, targetcset, pos + ComboPosition{0, -1}, up, diagonal, only_cset);
8425 if (pos.y < num_combos_height-1 && dir != up)
8426 fill2(targetcombo, targetcset, pos + ComboPosition{0, 1}, down, diagonal, only_cset);
8427 if (pos.x > 0 && dir != right)
8428 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 0}, left, diagonal, only_cset);
8429 if (pos.x < num_combos_width-1 && dir != left)
8430 fill2(targetcombo, targetcset, pos + ComboPosition{1, 0}, right, diagonal, only_cset);
8431
8432 if (diagonal == 1)
8433 {
8434 if (pos.y > 0 && pos.x > 0 && dir != r_down)
8435 fill2(targetcombo, targetcset, pos + ComboPosition{-1, -1}, l_up, diagonal, only_cset);
8436 if (pos.y < num_combos_height-1 && pos.x < num_combos_width-1 && dir != l_up)
8437 fill2(targetcombo, targetcset, pos + ComboPosition{1, 1}, r_down, diagonal, only_cset);
8438 if (pos.x > 0 && pos.y < num_combos_height-1 && dir != r_up)
8439 fill2(targetcombo, targetcset, pos + ComboPosition{-1, 1}, l_down, diagonal, only_cset);
8440 if (pos.x < num_combos_width-1 && pos.y > 0 && dir != l_down)
8441 fill2(targetcombo, targetcset, pos + ComboPosition{1, -1}, r_up, diagonal, only_cset);
8442 }
8443 }
8444
8445
8446 enum SnapMode
8447 {
8448 SNAP_NONE, SNAP_HALF, SNAP_WHOLE
8449 };
8450 static void snap_xy(int& x, int& y, SnapMode mode, roundType rounding, optional<int> max_x = nullopt, optional<int> max_y = nullopt)
8451 {
8452 if(mode == SNAP_NONE)
8453 {
8454 if(max_x) x = vbound(x,*max_x,0);
8455 if(max_y) y = vbound(y,*max_y,0);
8456 return;
8457 }
8458 int xoff = 0, yoff = 0;
8459 switch(rounding)
8460 {
8461 case ROUND_TO_0:
8462 rounding = ROUND_DOWN;
8463 break;
8464 case ROUND_AWAY_0:
8465 rounding = ROUND_UP;
8466 break;
8467 }
8468 int r = 0;
8469 switch(mode)
8470 {
8471 case SNAP_HALF:
8472 r = 8;
8473 break;
8474 case SNAP_WHOLE:
8475 r = 16;
8476 break;
8477 }
8478 assert(r > 0);
8479 // r must be a power of 2, for bitwise reasons
8480 switch(rounding)
8481 {
8482 case ROUND_DOWN:
8483 break;
8484 case ROUND_UP:
8485 xoff = ((x & (r-1)) ? r : 0);
8486 yoff = ((y & (r-1)) ? r : 0);
8487 break;
8488 case ROUND_NEAREST:
8489 xoff = ((x & (r-1)) >= (r/2) ? r : 0);
8490 yoff = ((y & (r-1)) >= (r/2) ? r : 0);
8491 break;
8492 }
8493 x = (x & ~(r-1)) + xoff;
8494 y = (y & ~(r-1)) + yoff;
8495 if(max_x && x >= *max_x) x = *max_x-r;
8496 else if(max_x && x < 0) x = 0;
8497 if(max_y && y >= *max_y) y = *max_y-r;
8498 else if(max_y && y < 0) y = 0;
8499 }
8500
8501 static void doxypos(byte &px2, byte &py2, int32_t color, SnapMode snap_mode,
8502 SnapMode shift_mode, bool immediately, int32_t cursoroffx,
8503 int32_t cursoroffy, int32_t iconw, int32_t iconh)
8504 {
8505 int32_t tempcb=ComboBrush;
8506 ComboBrush=0;
8507 MouseSprite::set(ZQM_POINT_BOX);
8508
8509 int viz_off_x = (active_visible_screen ? active_visible_screen->dx * 256 : 0);
8510 int viz_off_y = (active_visible_screen ? active_visible_screen->dy * 176 : 0);
8511
8512 int32_t oldpx=px2, oldpy=py2;
8513 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
8514 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
8515 showxypos_x=px2 + viz_off_x;
8516 showxypos_y=py2 + viz_off_y;
8517 showxypos_w=iconw;
8518 showxypos_h=iconh;
8519 showxypos_color=vc(color);
8520 showxypos_icon=!showxypos_dummy;
8521 bool canedit=false;
8522 bool done=false;
8523
8524 clear_tooltip();
8525
8526 while(!done && (!(gui_mouse_b()&2) || immediately))
8527 {
8528 if(!gui_mouse_b() || immediately)
8529 {
8530 canedit=true;
8531 }
8532
8533 // TODO: would be nice if these bounds were based on the individual screen.
8534 if(canedit && gui_mouse_b()==1 && isinRect(gui_mouse_x(),gui_mouse_y(),startxint,startyint,(startxint+(256*mapscreen_screenunit_scale)-1),(startyint+(176*mapscreen_screenunit_scale)-1)))
8535 {
8536 set_mouse_range(startxint,startyint,int32_t(startxint+(256*mapscreen_screenunit_scale)-1),int32_t(startyint+(176*mapscreen_screenunit_scale)-1));
8537
8538 double offx = 0, offy = 0;
8539 roundType rounding = ROUND_DOWN;
8540 if(DragCenterOfSquares)
8541 {
8542 offx -= iconw*mapscreen_single_scale/2;
8543 offy -= iconh*mapscreen_single_scale/2;
8544 rounding = ROUND_NEAREST;
8545 }
8546 int32_t x, y;
8547 do
8548 {
8549 x=int32_t((gui_mouse_x()-startxint+offx)/mapscreen_single_scale)-cursoroffx;
8550 y=int32_t((gui_mouse_y()-startyint+offy)/mapscreen_single_scale)-cursoroffy;
8551 showxypos_cursor_icon=true;
8552 showxypos_cursor_color = showxypos_color;
8553 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8554 showxypos_cursor_x = x-viz_off_x;
8555 showxypos_cursor_y = y-viz_off_y;
8556 snap_xy(showxypos_cursor_x, showxypos_cursor_y, _mode, rounding, 256, 176);
8557 showxypos_cursor_x += viz_off_x;
8558 showxypos_cursor_y += viz_off_y;
8559 custom_vsync();
8560 refresh(rALL | rNOCURSOR);
8561 int32_t xpos[2], ypos[2];
8562 int32_t x1,y1,x2,y2;
8563
8564 char b1[200] = {0};
8565 char b2[200] = {0};
8566 if(showxypos_dummy)
8567 strcpy(b1, "DUMMY MEASURING");
8568 else sprintf(b1, "%d %d",oldpx,oldpy);
8569 sprintf(b2, "%d %d (%d %d)",x-viz_off_x,y-viz_off_y,showxypos_cursor_x-viz_off_x,showxypos_cursor_y-viz_off_y);
8570
8571 int len[2] = {text_length(font,b1),text_length(font,b2)};
8572
8573 if(is_compact)
8574 {
8575 xpos[0] = 4;
8576 ypos[0] = layer_panel.y - 21;
8577 xpos[1] = xpos[0];
8578 ypos[1] = ypos[0]+10;
8579 }
8580 else
8581 {
8582 xpos[0] = 450;
8583 ypos[0] = 405;
8584 xpos[1] = xpos[0];
8585 ypos[1] = ypos[0]+10;
8586 }
8587
8588 x1 = xpos[0];
8589 y1 = ypos[0];
8590 x2 = xpos[0];
8591 y2 = ypos[0];
8592 for(auto q = 0; q < 2; ++q)
8593 {
8594 if(xpos[q] < x1)
8595 x1 = xpos[q];
8596 if(ypos[q] < y1)
8597 y1 = ypos[q];
8598 if(ypos[q] > y2)
8599 y2 = ypos[q];
8600 if(xpos[q] + len[q] > x2)
8601 x2 = xpos[q] + len[q];
8602 }
8603 x1 -= 4;
8604 y1 -= 2;
8605 y2 += text_height(font)+2;
8606
8607 auto minx = zc_min(xpos[0],xpos[1]);
8608 auto miny = zc_min(ypos[0],ypos[1]);
8609 rectfill(screen,x1,y1,x2,y2,vc(0));
8610 textprintf_ex(screen,font,xpos[0],ypos[0],vc(15),vc(0),"%s",b1);
8611 textprintf_ex(screen,font,xpos[1],ypos[1],vc(15),vc(0),"%s",b2);
8612 update_hw_screen();
8613 }
8614 while(gui_mouse_b()==1);
8615
8616 if(gui_mouse_b()==0)
8617 {
8618 auto _mode = (key[KEY_LSHIFT] || key[KEY_RSHIFT]) ? shift_mode : snap_mode;
8619 int x2 = vbound(x-viz_off_x,0,255);
8620 int y2 = vbound(y-viz_off_y,0,175);
8621 snap_xy(x2, y2, _mode, rounding, 256, 176);
8622 px2=byte(x2);
8623 py2=byte(y2);
8624 }
8625
8626 set_mouse_range(0,0,zq_screen_w-1,zq_screen_h-1);
8627 done=true;
8628 }
8629
8630 if(keypressed())
8631 {
8632 switch(readkey()>>8)
8633 {
8634 case KEY_ESC:
8635 case KEY_ENTER:
8636 goto finished;
8637 }
8638 }
8639
8640 custom_vsync();
8641 refresh(rALL | rNOCURSOR);
8642 }
8643
8644 finished:
8645 MouseSprite::set(ZQM_NORMAL);
8646 refresh(rMAP+rMENU);
8647
8648 while(gui_mouse_b())
8649 {
8650 /* do nothing */
8651 rest(1);
8652 }
8653
8654 showxypos_x=-1000;
8655 showxypos_y=-1000;
8656 showxypos_color=-1000;
8657 showxypos_ffc=-1000;
8658 showxypos_icon=false;
8659 showxypos_cursor_x=-1000;
8660 showxypos_cursor_y=-1000;
8661 showxypos_cursor_icon=false;
8662 showxypos_cursor_color=-1000;
8663 showxypos_dummy=false;
8664
8665 if(px2!=oldpx||py2!=oldpy)
8666 {
8667 saved=false;
8668 }
8669
8670 ComboBrush=tempcb;
8671 }
8672 static void doxypos(byte &px2,byte &py2,int32_t color,SnapMode snap_mode, optional<SnapMode> shift_mode = nullopt)
8673 {
8674 doxypos(px2,py2,color,snap_mode,shift_mode ? *shift_mode : snap_mode,false,0,0,16,16);
8675 }
8676
8677 bool placing_flags = false;
8678 void doflags()
8679 {
8680 placing_flags = true;
8681 int of=Flags;
8682 Flags=cFLAGS;
8683 refresh(rMAP | rNOCURSOR);
8684
8685 bool canedit=false;
8686 bool didShift = false;
8687 int tFlag = Flag;
8688 while(!(gui_mouse_b()&2) && !handle_close_btn_quit())
8689 {
8690 int x=gui_mouse_x();
8691 int y=gui_mouse_y();
8692 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
8693 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
8694 int startxint=mapscreen_x+(showedges?int(16*mapscreen_single_scale):0);
8695 int startyint=mapscreen_y+(showedges?int(16*mapscreen_single_scale):0);
8696 int cx=(x-startxint)/int(16*mapscreen_single_scale);
8697 int cy=(y-startyint)/int(16*mapscreen_single_scale);
8698 ComboPosition combo_pos = {cx, cy};
8699 int c = combo_pos.truncate();
8700
8701 if(!gui_mouse_b())
8702 canedit=true;
8703 bool shift = key[KEY_LSHIFT] || key[KEY_RSHIFT];
8704
8705 if(canedit && gui_mouse_b()==1 && isinRect(x,y,startxint,startyint,int(startx+(256*mapscreen_screenunit_scale)-1),int(starty+(176*mapscreen_screenunit_scale)-1)))
8706 {
8707 mapscr* cur_scr = Map.Scr(combo_pos, CurrentLayer);
8708 if (!cur_scr) continue;
8709
8710 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
8711
8712 if(key[KEY_ALT]||key[KEY_ALTGR])
8713 Flag = cur_scr->sflag[c];
8714 else
8715 {
8716 saved=false;
8717 int tflag = Flag;
8718 if(shift)
8719 Flag = mfNONE;
8720 if(CurrentLayer!=0)
8721 {
8722 // Notify if they are using a flag that doesn't work on this layer.
8723 if(!skipLayerWarning && ((Flag >= mfTRAP_H && Flag < mfPUSHD) || (Flag == mfFAIRY) || (Flag == mfMAGICFAIRY)
8724 || (Flag == mfALLFAIRY) || (Flag == mfRAFT) || (Flag == mfRAFT_BRANCH)
8725 || (Flag == mfDIVE_ITEM) || (Flag == mfARMOS_SECRET) || (Flag == mfNOENEMY)
8726 || (Flag == mfZELDA)))
8727 {
8728 InfoDialog("Notice","You are currently working on layer "
8729 +to_string(CurrentLayer)
8730 +". This combo flag does not function on layers above '0'.").show();
8731 }
8732 if(!skipLayerWarning && CurrentLayer > 2 &&
8733 ((Flag == mfBLOCKHOLE) || (Flag >= mfPUSHD && Flag < mfNOBLOCKS)
8734 || (Flag == mfPUSHUD) || (Flag == mfPUSH4)))
8735 {
8736 InfoDialog("Notice","You are currently working on layer "
8737 +to_string(CurrentLayer)
8738 +". This combo flag does not function on layers above '2'.").show();
8739 }
8740 }
8741 if(CHECK_CTRL_CMD)
8742 {
8743 switch(fill_type)
8744 {
8745 case 0:
8746 flood_flag();
8747 break;
8748
8749 case 1:
8750 case 3:
8751 fill_4_flag();
8752 break;
8753
8754 case 2:
8755 case 4:
8756 fill_8_flag();
8757 break;
8758 }
8759 }
8760 else
8761 {
8762 Map.DoSetFlagCommand(combo_pos, Flag);
8763 }
8764 Flag = tflag;
8765 }
8766 }
8767
8768 if(mouse_z)
8769 {
8770 for(int i=0; i<abs(mouse_z); ++i)
8771 {
8772 if(mouse_z>0)
8773 onIncreaseFlag();
8774 else
8775 onDecreaseFlag();
8776 }
8777
8778 position_mouse_z(0);
8779 }
8780
8781 if(keypressed())
8782 {
8783 int k = readkey();
8784 switch(k>>8)
8785 {
8786 case KEY_ESC:
8787 case KEY_ENTER:
8788 goto finished;
8789 }
8790 object_message(dialogs+1, MSG_XCHAR, k);
8791 Flags=cFLAGS;
8792 }
8793
8794 MouseSprite::set(ZQM_FLAG_0+(shift?0:Flag%16));
8795
8796 refresh(rALL | rCLEAR | rNOCURSOR);
8797 custom_vsync();
8798 }
8799
8800 finished:
8801 Flags=of;
8802 placing_flags = false;
8803 MouseSprite::set(ZQM_NORMAL);
8804 refresh(rMAP+rMENU);
8805
8806 while(gui_mouse_b())
8807 {
8808 /* do nothing */
8809 rest(1);
8810 }
8811 }
8812
8813 // Drag FFCs around
8814 static void moveffc(int i, int cx, int cy)
8815 {
8816 mapscr* scr = active_visible_screen->scr;
8817 int screen = active_visible_screen->screen;
8818
8819 int32_t ffx = vbound(scr->ffcs[i].x.getFloor(),0,240);
8820 int32_t ffy = vbound(scr->ffcs[i].y.getFloor(),0,160);
8821 int32_t offx = ffx, offy = ffy;
8822 showxypos_ffc = i;
8823 doxypos((byte&)ffx,(byte&)ffy,15,SNAP_HALF,SNAP_NONE,true,0,0,(scr->ffTileWidth(i)*16),(scr->ffTileHeight(i)*16));
8824 if(ffx > 240) ffx = 240;
8825 if(ffy > 160) ffy = 160;
8826 if((ffx != offx) || (ffy != offy))
8827 {
8828 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
8829 set_ffc_data.x = ffx;
8830 set_ffc_data.y = ffy;
8831 Map.DoSetFFCCommand(Map.getCurrMap(), screen, i, set_ffc_data);
8832 saved = false;
8833 }
8834 }
8835
8836 void set_brush_width(int32_t width);
8837 void set_brush_height(int32_t height);
8838
8839 int32_t set_brush_width_1()
8840 {
8841 set_brush_width(1);
8842 return D_O_K;
8843 }
8844 int32_t set_brush_width_2()
8845 {
8846 set_brush_width(2);
8847 return D_O_K;
8848 }
8849 int32_t set_brush_width_3()
8850 {
8851 set_brush_width(3);
8852 return D_O_K;
8853 }
8854 int32_t set_brush_width_4()
8855 {
8856 set_brush_width(4);
8857 return D_O_K;
8858 }
8859 int32_t set_brush_width_5()
8860 {
8861 set_brush_width(5);
8862 return D_O_K;
8863 }
8864 int32_t set_brush_width_6()
8865 {
8866 set_brush_width(6);
8867 return D_O_K;
8868 }
8869 int32_t set_brush_width_7()
8870 {
8871 set_brush_width(7);
8872 return D_O_K;
8873 }
8874 int32_t set_brush_width_8()
8875 {
8876 set_brush_width(8);
8877 return D_O_K;
8878 }
8879 int32_t set_brush_width_9()
8880 {
8881 set_brush_width(9);
8882 return D_O_K;
8883 }
8884 int32_t set_brush_width_10()
8885 {
8886 set_brush_width(10);
8887 return D_O_K;
8888 }
8889 int32_t set_brush_width_11()
8890 {
8891 set_brush_width(11);
8892 return D_O_K;
8893 }
8894 int32_t set_brush_width_12()
8895 {
8896 set_brush_width(12);
8897 return D_O_K;
8898 }
8899 int32_t set_brush_width_13()
8900 {
8901 set_brush_width(13);
8902 return D_O_K;
8903 }
8904 int32_t set_brush_width_14()
8905 {
8906 set_brush_width(14);
8907 return D_O_K;
8908 }
8909 int32_t set_brush_width_15()
8910 {
8911 set_brush_width(15);
8912 return D_O_K;
8913 }
8914 int32_t set_brush_width_16()
8915 {
8916 set_brush_width(16);
8917 return D_O_K;
8918 }
8919
8920 int32_t set_brush_height_1()
8921 {
8922 set_brush_height(1);
8923 return D_O_K;
8924 }
8925 int32_t set_brush_height_2()
8926 {
8927 set_brush_height(2);
8928 return D_O_K;
8929 }
8930 int32_t set_brush_height_3()
8931 {
8932 set_brush_height(3);
8933 return D_O_K;
8934 }
8935 int32_t set_brush_height_4()
8936 {
8937 set_brush_height(4);
8938 return D_O_K;
8939 }
8940 int32_t set_brush_height_5()
8941 {
8942 set_brush_height(5);
8943 return D_O_K;
8944 }
8945 int32_t set_brush_height_6()
8946 {
8947 set_brush_height(6);
8948 return D_O_K;
8949 }
8950 int32_t set_brush_height_7()
8951 {
8952 set_brush_height(7);
8953 return D_O_K;
8954 }
8955 int32_t set_brush_height_8()
8956 {
8957 set_brush_height(8);
8958 return D_O_K;
8959 }
8960 int32_t set_brush_height_9()
8961 {
8962 set_brush_height(9);
8963 return D_O_K;
8964 }
8965 int32_t set_brush_height_10()
8966 {
8967 set_brush_height(10);
8968 return D_O_K;
8969 }
8970 int32_t set_brush_height_11()
8971 {
8972 set_brush_height(11);
8973 return D_O_K;
8974 }
8975
8976
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu brush_width_menu
8977 153 {
8978
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "1", set_brush_width_1 },
8979
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2", set_brush_width_2 },
8980
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "3", set_brush_width_3 },
8981
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "4", set_brush_width_4 },
8982
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "5", set_brush_width_5 },
8983
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "6", set_brush_width_6 },
8984
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "7", set_brush_width_7 },
8985
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "8", set_brush_width_8 },
8986
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "9", set_brush_width_9 },
8987
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "10", set_brush_width_10 },
8988
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "11", set_brush_width_11 },
8989
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "12", set_brush_width_12 },
8990
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "13", set_brush_width_13 },
8991
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "14", set_brush_width_14 },
8992
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "15", set_brush_width_15 },
8993
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "16", set_brush_width_16 },
8994 };
8995
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu brush_height_menu
8996 108 {
8997
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "1", set_brush_height_1 },
8998
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2", set_brush_height_2 },
8999
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "3", set_brush_height_3 },
9000
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "4", set_brush_height_4 },
9001
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "5", set_brush_height_5 },
9002
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "6", set_brush_height_6 },
9003
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "7", set_brush_height_7 },
9004
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "8", set_brush_height_8 },
9005
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "9", set_brush_height_9 },
9006
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "10", set_brush_height_10 },
9007
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "11", set_brush_height_11 },
9008 };
9009
9010 int toggle_autobrush();
9011 int toggle_combobrush();
9012 int toggle_floatbrush();
9013 enum
9014 {
9015 MENUID_BRUSH_AUTOBRUSH,
9016 MENUID_BRUSH_WIDTH,
9017 MENUID_BRUSH_HEIGHT,
9018 MENUID_BRUSH_COMBOBRUSH,
9019 MENUID_BRUSH_FLOATBRUSH,
9020 };
9021
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu brush_menu
9022 54 {
9023
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "AutoBrush", toggle_autobrush, MENUID_BRUSH_AUTOBRUSH },
9024
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Brush Width ", &brush_width_menu, MENUID_BRUSH_WIDTH },
9025
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Brush Height ", &brush_height_menu, MENUID_BRUSH_HEIGHT },
9026
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "ComboBrush", toggle_combobrush, MENUID_BRUSH_COMBOBRUSH },
9027
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "FloatBrush", toggle_floatbrush, MENUID_BRUSH_FLOATBRUSH },
9028 };
9029 int toggle_autobrush()
9030 {
9031 AutoBrush = AutoBrush ? 0 : 1;
9032 BrushWidth = BrushHeight = 1;
9033 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9034 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9035 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9036 zc_set_config("zquest","autobrush",AutoBrush);
9037 return D_O_K;
9038 }
9039 int toggle_combobrush()
9040 {
9041 ComboBrush = ComboBrush ? 0 : 1;
9042 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9043 zc_set_config("zquest","combo_brush",ComboBrush);
9044 return D_O_K;
9045 }
9046 int toggle_floatbrush()
9047 {
9048 FloatBrush = FloatBrush ? 0 : 1;
9049 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9050 zc_set_config("zquest","float_brush",FloatBrush);
9051 return D_O_K;
9052 }
9053
9054 int32_t set_flood();
9055 int32_t set_fill_4();
9056 int32_t set_fill_8();
9057 int32_t set_fill2_4();
9058 int32_t set_fill2_8();
9059
9060 // Sets every combo.
9061 void flood()
9062 {
9063 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9064 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9065 if (!scr || !scr->is_valid())
9066 return;
9067
9068 saved=false;
9069
9070 bool include_combos = !(key[KEY_LSHIFT]||key[KEY_RSHIFT]);
9071
9072 int num_combos_width = 16 * Map.getViewSize();
9073 int num_combos_height = 11 * Map.getViewSize();
9074
9075 Map.StartListCommand();
9076 for (int x = 0; x < num_combos_width; x++)
9077 {
9078 for (int y = 0; y < num_combos_height; y++)
9079 {
9080 ComboPosition pos = {x, y};
9081 mapscr* scr = Map.Scr(pos, CurrentLayer);
9082 if (!scr || !scr->is_valid())
9083 continue;
9084
9085 if (draw_mode == dm_auto)
9086 draw_autocombo(pos, gui_mouse_b() & 2);
9087 else
9088 Map.DoSetComboCommand(pos, include_combos ? Combo : -1, CSet);
9089 }
9090 }
9091 Map.FinishListCommand();
9092
9093 refresh(rMAP+rSCRMAP);
9094 }
9095 void flood_flag()
9096 {
9097 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9098 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9099 if (!scr || !scr->is_valid())
9100 return;
9101
9102 saved=false;
9103
9104 int num_combos_width = 16 * Map.getViewSize();
9105 int num_combos_height = 11 * Map.getViewSize();
9106
9107 Map.StartListCommand();
9108 for (int x = 0; x < num_combos_width; x++)
9109 {
9110 for (int y = 0; y < num_combos_height; y++)
9111 {
9112 ComboPosition pos = {x, y};
9113 mapscr* scr = Map.Scr(pos, CurrentLayer);
9114 if (!scr || !scr->is_valid())
9115 continue;
9116
9117 Map.DoSetFlagCommand(pos, Flag);
9118 }
9119 }
9120 Map.FinishListCommand();
9121
9122 refresh(rMAP+rSCRMAP);
9123 }
9124
9125 void fill_4()
9126 {
9127 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9128 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9129 if (!scr)
9130 return;
9131
9132 int c = pos.truncate();
9133 if (draw_mode == dm_cpool || draw_mode == dm_auto
9134 || (scr->cset[c]!=CSet || (scr->data[c]!=Combo && !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9135 {
9136 saved=false;
9137
9138 Map.StartListCommand();
9139 if (draw_mode == dm_auto && (combo_autos[combo_auto_pos].getType() == AUTOCOMBO_FENCE ||
9140 combo_autos[combo_auto_pos].getType() == AUTOCOMBO_Z4))
9141 {
9142 draw_autocombo_command(pos);
9143 }
9144 else
9145 {
9146 bool allow_diagonal = false;
9147 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT] || key[KEY_RSHIFT]));
9148 }
9149 Map.FinishListCommand();
9150 refresh(rMAP+rSCRMAP);
9151 }
9152 }
9153 void fill_4_flag()
9154 {
9155 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9156 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9157 if (!scr)
9158 return;
9159
9160 int flag = scr->sflag[pos.truncate()];
9161 if (flag != Flag)
9162 {
9163 saved=false;
9164
9165 Map.StartListCommand();
9166 bool allow_diagonal = false;
9167 fill_flag(flag, pos, allow_diagonal);
9168 Map.FinishListCommand();
9169 refresh(rMAP+rSCRMAP);
9170 }
9171 }
9172 void fill_8()
9173 {
9174 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9175 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9176 if (!scr)
9177 return;
9178
9179 int c = pos.truncate();
9180 if (draw_mode == dm_cpool || draw_mode == dm_auto
9181 || (scr->cset[c] != CSet ||
9182 (scr->data[c] != Combo &&
9183 !(key[KEY_LSHIFT]||key[KEY_RSHIFT]))))
9184 {
9185 saved=false;
9186
9187 Map.StartListCommand();
9188 bool allow_diagonal = true;
9189 fill(scr->data[c], scr->cset[c], pos, allow_diagonal, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9190 Map.FinishListCommand();
9191
9192 refresh(rMAP+rSCRMAP);
9193 }
9194 }
9195 void fill_8_flag()
9196 {
9197 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9198 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9199 if (!scr)
9200 return;
9201
9202 int flag = scr->sflag[pos.truncate()];
9203 if (flag != Flag)
9204 {
9205 saved=false;
9206
9207 Map.StartListCommand();
9208 bool allow_diagonal = true;
9209 fill_flag(flag, pos, allow_diagonal);
9210 Map.FinishListCommand();
9211 refresh(rMAP+rSCRMAP);
9212 }
9213 }
9214
9215 void fill2_4()
9216 {
9217 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9218 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9219 if (!scr)
9220 return;
9221
9222 saved=false;
9223
9224 Map.StartListCommand();
9225 fill2(Combo, CSet, pos, 255, 0, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9226 Map.FinishListCommand();
9227 refresh(rMAP+rSCRMAP);
9228 }
9229
9230 void fill2_8()
9231 {
9232 ComboPosition pos = get_mapscreen_mouse_combo_pos();
9233 mapscr* scr = Map.ScrMakeValid(pos, CurrentLayer);
9234 if (!scr)
9235 return;
9236
9237 saved=false;
9238
9239 Map.StartListCommand();
9240 fill2(Combo, CSet, pos, 255, 1, (key[KEY_LSHIFT]||key[KEY_RSHIFT]));
9241 Map.FinishListCommand();
9242
9243 refresh(rMAP+rSCRMAP);
9244 }
9245
9246
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu fill_menu
9247 54 {
9248
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Flood", set_flood, 0 },
9249
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Fill (4-way)", set_fill_4, 1 },
9250
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Fill (8-way)", set_fill_8, 2 },
9251
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Fill2 (4-way)", set_fill2_4, 3 },
9252
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Fill2 (8-way)", set_fill2_8, 4 },
9253 };
9254 void set_filltype(int ty)
9255 {
9256 fill_type = ty;
9257 fill_menu.select_only_uid(ty);
9258 }
9259
9260 int32_t set_flood()
9261 {
9262 set_filltype(0);
9263 return D_O_K;
9264 }
9265
9266 int32_t set_fill_4()
9267 {
9268 set_filltype(1);
9269 return D_O_K;
9270 }
9271
9272 int32_t set_fill_8()
9273 {
9274 set_filltype(2);
9275 return D_O_K;
9276 }
9277
9278 int32_t set_fill2_4()
9279 {
9280 set_filltype(3);
9281 return D_O_K;
9282 }
9283
9284 int32_t set_fill2_8()
9285 {
9286 set_filltype(4);
9287 return D_O_K;
9288 }
9289
9290 int32_t draw_block_1_2()
9291 {
9292 draw_block(mouse_combo_pos,1,2);
9293 return D_O_K;
9294 }
9295
9296 int32_t draw_block_2_1()
9297 {
9298 draw_block(mouse_combo_pos,2,1);
9299 return D_O_K;
9300 }
9301
9302 int32_t draw_block_2_2()
9303 {
9304 draw_block(mouse_combo_pos,2,2);
9305 return D_O_K;
9306 }
9307
9308 int32_t draw_block_2_3()
9309 {
9310 draw_block(mouse_combo_pos,2,3);
9311 return D_O_K;
9312 }
9313
9314 int32_t draw_block_3_2()
9315 {
9316 draw_block(mouse_combo_pos,3,2);
9317 return D_O_K;
9318 }
9319
9320 int32_t draw_block_3_3()
9321 {
9322 draw_block(mouse_combo_pos,3,3);
9323 return D_O_K;
9324 }
9325
9326 int32_t draw_block_4_2()
9327 {
9328 draw_block(mouse_combo_pos,4,2);
9329 return D_O_K;
9330 }
9331
9332 int32_t draw_block_4_4()
9333 {
9334 draw_block(mouse_combo_pos,4,4);
9335 return D_O_K;
9336 }
9337
9338
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu draw_block_menu
9339 81 {
9340
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "1x2", draw_block_1_2 },
9341
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2x1", draw_block_2_1 },
9342
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2x2", draw_block_2_2 },
9343
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "2x3", draw_block_2_3 },
9344
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "3x2", draw_block_3_2 },
9345
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "3x3", draw_block_3_3 },
9346
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "4x2", draw_block_4_2 },
9347
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "4x4", draw_block_4_4 },
9348 };
9349
9350
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu paste_screen_menu
9351 45 {
9352
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste", onPaste },
9353
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste All", onPasteAll },
9354
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste to All", onPasteToAll },
9355
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste All to All", onPasteAllToAll },
9356 };
9357
9358 int32_t scrollto_cmb(int32_t cid)
9359 {
9360 auto& sqr = combolist[current_combolist];
9361 int32_t res = vbound(cid-(sqr.w*sqr.h/2),0,MAXCOMBOS-(sqr.w*sqr.h));
9362 res -= res%sqr.w;
9363 return res;
9364 }
9365 int32_t scrollto_alias(int32_t alid)
9366 {
9367 auto& sqr = comboaliaslist[current_comboalist];
9368 int32_t res = vbound(alid-(sqr.w*sqr.h/2),0,MAXCOMBOALIASES-(sqr.w*sqr.h));
9369 res -= res%sqr.w;
9370 return res;
9371 }
9372
9373 int32_t scrollto_cpool(int32_t cpid)
9374 {
9375 auto& sqr = comboaliaslist[current_cpoollist];
9376 int32_t res = vbound(cpid-(sqr.w*sqr.h/2),0,MAXCOMBOPOOLS-(sqr.w*sqr.h));
9377 res -= res%sqr.w;
9378 return res;
9379 }
9380
9381 int32_t scrollto_cauto(int32_t caid)
9382 {
9383 auto& sqr = comboaliaslist[current_cautolist];
9384 int32_t res = vbound(caid - (sqr.w * sqr.h / 2), 0, MAXCOMBOPOOLS - (sqr.w * sqr.h));
9385 res -= res % sqr.w;
9386 return res;
9387 }
9388
9389 void add_favorite_combo_block(int32_t favind, int32_t cid, bool force)
9390 {
9391 int32_t w = vbound(BrushWidth, 1, 4);
9392 int32_t h = vbound(BrushHeight, 1, 7);
9393 for (int32_t xi = 0; xi < w; ++xi)
9394 {
9395 for (int32_t yi = 0; yi < h; ++yi)
9396 {
9397 int32_t cx = cid % 4;
9398 int32_t cy = cid / 4;
9399 int32_t cc = (cy + yi) * 4 + cx + xi;
9400 int32_t fx = favind % FAVORITECOMBO_PER_ROW;
9401 int32_t fy = favind / FAVORITECOMBO_PER_ROW;
9402 int32_t fc = (fy + yi) * FAVORITECOMBO_PER_ROW + fx + xi + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
9403
9404 if (cx + xi < 4 && cc < MAXCOMBOS && fx + xi < FAVORITECOMBO_PER_ROW && fy + yi < FAVORITECOMBO_PER_COLUMN)
9405 {
9406 if (favorite_combos[fc] < 0 || force)
9407 {
9408 favorite_combo_modes[fc] = dm_normal;
9409 favorite_combos[fc] = cc;
9410 }
9411 }
9412 }
9413 }
9414 }
9415
9416 void onRCSelectCombo(int32_t c)
9417 {
9418 int32_t drawmap, drawscr;
9419
9420 if(CurrentLayer==0)
9421 {
9422 drawmap=Map.getCurrMap();
9423 drawscr=Map.getCurrScr();
9424 }
9425 else
9426 {
9427 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9428 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9429 }
9430 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9431 if(!draw_mapscr) return;
9432
9433 Combo=draw_mapscr->data[c];
9434 if(AutoBrush)
9435 BrushWidth = BrushHeight = 1;
9436 }
9437
9438 void onRCScrollToombo(int32_t c)
9439 {
9440 int32_t drawmap, drawscr;
9441
9442 if(CurrentLayer==0)
9443 {
9444 drawmap=Map.getCurrMap();
9445 drawscr=Map.getCurrScr();
9446 }
9447 else
9448 {
9449 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
9450 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
9451 }
9452 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
9453 if(!draw_mapscr) return;
9454
9455 auto& sqr = combolist[current_combolist];
9456 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
9457 }
9458
9459 enum
9460 {
9461 MENUID_RCSCREEN_PASTE,
9462 MENUID_RCSCREEN_ADVPASTE,
9463 MENUID_RCSCREEN_SPECPASTE,
9464 };
9465
1/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
9 static NewMenu rc_menu_screen
9466 45 {
9467
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Copy Screen", onCopy },
9468
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "Paste Screen", &paste_screen_menu, MENUID_RCSCREEN_PASTE },
9469
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "...Advanced Paste", &paste_menu, MENUID_RCSCREEN_ADVPASTE },
9470
2/4
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
9 { "...Special Paste", &paste_item_menu, MENUID_RCSCREEN_SPECPASTE },
9471 };
9472
9473 void call_options_dlg();
9474 int32_t onOptions()
9475 {
9476 call_options_dlg();
9477 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
9478 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
9479 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
9480 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
9481 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
9482 return D_O_K;
9483 }
9484
9485 void follow_twarp(int warpindex)
9486 {
9487 if(warpindex >= 4)
9488 {
9489 InfoDialog("Random Tile Warp",
9490 "This is a random tile warp combo, so it chooses"
9491 " randomly between the screen's four Tile Warps.").show();
9492 warpindex=zc_oldrand()&3;
9493 }
9494
9495 int32_t tm = Map.getCurrMap();
9496 int32_t ts = Map.getCurrScr();
9497 int32_t wt = Map.CurrScr()->tilewarptype[warpindex];
9498
9499 if(wt==wtCAVE || wt==wtNOWARP)
9500 {
9501 char buf[56];
9502 InfoDialog(warptype_string[wt],fmt::format("This screen's Tile Warp {} is set to {}, so it doesn't lead to another screen.",'A'+warpindex,warptype_string[wt]));
9503 return;
9504 }
9505
9506 Map.dowarp(0,warpindex);
9507
9508 if(ts!=Map.getCurrScr() || tm!=Map.getCurrMap())
9509 {
9510 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(warpindex*2))&3;
9511 FlashWarpClk = 32;
9512 }
9513 }
9514 void edit_twarp(int warpindex)
9515 {
9516 if(warpindex>=4)
9517 {
9518 InfoDialog("Random Tile Warp",
9519 "This is a random tile warp combo, so it chooses"
9520 " randomly between the screen's four Tile Warps.").show();
9521 warpindex=zc_oldrand()&3;
9522 }
9523
9524 if(warpindex > -1 && warpindex < 4)
9525 onTileWarpIndex(warpindex);
9526 }
9527
9528 int toggle_linked_scrolling()
9529 {
9530 LinkedScroll = LinkedScroll ? 0 : 1;
9531 zc_set_config("zquest","linked_comboscroll",LinkedScroll);
9532 return D_O_K;
9533 }
9534 void on_scroll_cpane()
9535 {
9536 switch (draw_mode)
9537 {
9538 case dm_alias:
9539 combo_alistpos[current_comboalist] = scrollto_alias(combo_apos);
9540 break;
9541 case dm_cpool:
9542 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
9543 break;
9544 case dm_auto:
9545 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
9546 break;
9547 default:
9548 First[current_combolist] = scrollto_cmb(Combo);
9549 break;
9550 }
9551 }
9552 void on_edit_cpane()
9553 {
9554 switch (draw_mode)
9555 {
9556 case dm_alias:
9557 onEditComboAlias();
9558 break;
9559 case dm_cpool:
9560 onEditComboPool();
9561 break;
9562 case dm_auto:
9563 onEditAutoCombo();
9564 break;
9565 default:
9566 reset_combo_animations();
9567 reset_combo_animations2();
9568 edit_combo(Combo, true, CSet);
9569 setup_combo_animations();
9570 setup_combo_animations2();
9571 break;
9572 }
9573 }
9574 void on_cpane_page()
9575 {
9576 switch(draw_mode)
9577 {
9578 case dm_normal:
9579 combo_screen(Combo>>8,Combo);
9580 break;
9581 case dm_alias:
9582 call_alias_pages(combo_apos);
9583 break;
9584 case dm_auto:
9585 call_autoc_pages(combo_auto_pos);
9586 break;
9587 case dm_cpool:
9588 call_cpool_pages(combo_pool_pos);
9589 break;
9590 }
9591 }
9592 void open_cpane_tilepage()
9593 {
9594 onGotoTiles(combobuf[Combo].o_tile);
9595 }
9596 static int _clicked_fav = 0;
9597 void fav_rc_remove()
9598 {
9599 favorite_combo_modes[_clicked_fav] = dm_normal;
9600 favorite_combos[_clicked_fav] = -1;
9601 saved = false;
9602 }
9603 void popup_favorites_rc(int f, int x, int y)
9604 {
9605 _clicked_fav = f;
9606 string type;
9607 switch (draw_mode)
9608 {
9609 case dm_alias:
9610 type = "Alias";
9611 break;
9612 case dm_cpool:
9613 type = "Pool";
9614 break;
9615 case dm_auto:
9616 type = "Autocombo";
9617 break;
9618 case dm_normal:
9619 type = "Combo";
9620 break;
9621 default: return;
9622 }
9623 NewMenu rcmenu
9624 {
9625 { fmt::format("Scroll to {}", type), on_scroll_cpane },
9626 { fmt::format("Edit {}", type), on_edit_cpane },
9627 { fmt::format("Open {} Page", type), on_cpane_page },
9628 { fmt::format("Remove Fav {}", type), fav_rc_remove },
9629 };
9630 switch (draw_mode)
9631 {
9632 case dm_normal:
9633 rcmenu.add({
9634 {},
9635 { "Open Tile Page", open_cpane_tilepage },
9636 });
9637 break;
9638 }
9639 rcmenu.pop(x, y);
9640 }
9641 void popup_cpane_rc(int x, int y)
9642 {
9643 string type;
9644 switch (draw_mode)
9645 {
9646 case dm_alias:
9647 type = "Alias";
9648 break;
9649 case dm_cpool:
9650 type = "Pool";
9651 break;
9652 case dm_auto:
9653 type = "Autocombo";
9654 break;
9655 case dm_normal:
9656 type = "Combo";
9657 break;
9658 default: return;
9659 }
9660 NewMenu rcmenu;
9661 switch(draw_mode)
9662 {
9663 case dm_normal:
9664 rcmenu.add({
9665 { fmt::format("Edit {}", type), on_edit_cpane },
9666 { fmt::format("Open {} Page", type), on_cpane_page },
9667 { "Open Tile Page", open_cpane_tilepage },
9668 { "Combo Locations", onComboLocationReport },
9669 {},
9670 { "Scroll to Page...", onGotoPage },
9671 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9672 });
9673 break;
9674 case dm_alias:
9675 case dm_cpool:
9676 case dm_auto:
9677 rcmenu.add({
9678 { fmt::format("Edit {}", type), on_edit_cpane },
9679 { fmt::format("Open {} Page", type), on_cpane_page },
9680 {},
9681 { "Scroll to Page...", onGotoPage },
9682 { "Linked Scrolling", toggle_linked_scrolling, nullopt, LinkedScroll ? MFL_SEL : 0 },
9683 });
9684 break;
9685 }
9686 rcmenu.pop(x, y);
9687 }
9688
9689 void set_brush_width(int32_t width)
9690 {
9691 BrushWidth = width;
9692 for(int q = 0; q < brush_width_menu.size(); ++q)
9693 brush_width_menu.at(q)->select(q==BrushWidth-1);
9694 refresh(rALL);
9695 }
9696
9697 void set_brush_height(int32_t height)
9698 {
9699 BrushHeight = height;
9700 for(int q = 0; q < brush_height_menu.size(); ++q)
9701 brush_height_menu.at(q)->select(q==BrushHeight-1);
9702 refresh(rALL);
9703 }
9704
9705 void restore_mouse()
9706 {
9707 ComboBrushPause=1;
9708 MouseSprite::set(ZQM_NORMAL);
9709 }
9710
9711 static int32_t comboa_cnt=0;
9712 static int32_t combop_cnt=0;
9713 static int32_t layer_cnt=0;
9714
9715 static char paste_ffc_menu_text[21];
9716 static char paste_ffc_menu_text2[21];
9717 static char follow_warp_menu_text[21];
9718 static char follow_warp_menu_text2[21];
9719
9720 static int fake_mouse_b(){return 0;}
9721 static int (*mouseb_proc)();
9722 static bool killed_mouse = false;
9723 void zq_killmouse()
9724 {
9725 if(killed_mouse) return;
9726 mouseb_proc = gui_mouse_b;
9727 gui_mouse_b = fake_mouse_b;
9728 killed_mouse = true;
9729 }
9730 void zq_restoremouse()
9731 {
9732 if(!killed_mouse) return;
9733 gui_mouse_b = mouseb_proc;
9734 killed_mouse = false;
9735 }
9736
9737
9738 void domouse()
9739 {
9740 static int mouse_down = 0;
9741 static int32_t scrolldelay = 0;
9742 auto mousexy = zc_get_mouse();
9743 auto x = mousexy.first;
9744 auto y = mousexy.second;
9745 double startx=mapscreen_x+(showedges?(16*mapscreen_single_scale):0);
9746 double starty=mapscreen_y+(showedges?(16*mapscreen_single_scale):0);
9747 int32_t startxint=mapscreen_x+(showedges?int32_t(16*mapscreen_single_scale):0);
9748 int32_t startyint=mapscreen_y+(showedges?int32_t(16*mapscreen_single_scale):0);
9749 int32_t cx=(x-startx)/(16*mapscreen_single_scale);
9750 int32_t cy=(y-starty)/(16*mapscreen_single_scale);
9751 ComboPosition combo_pos = {cx, cy};
9752
9753 if (draw_mode == dm_auto)
9754 {
9755 if (combo_pos != mouse_combo_pos)
9756 combobrushoverride = get_autocombo_floating_cid(combo_pos, false);
9757 }
9758 else
9759 combobrushoverride = -1;
9760
9761 mouse_combo_pos = combo_pos;
9762 update_combobrush();
9763
9764 ++scrolldelay;
9765
9766 bool x_on_list = false;
9767 for(auto q = 0; q < num_combo_cols; ++q)
9768 {
9769 if((x>=combolist[q].x) && (x<combolist[q].x+(combolist[q].xscale*combolist[q].w)))
9770 {
9771 x_on_list = true;
9772 break;
9773 }
9774 }
9775 if(MouseScroll && x_on_list && (key[KEY_LSHIFT] || key[KEY_RSHIFT] || (scrolldelay&3)==0))
9776 {
9777 int32_t test_list=0;
9778
9779 for(test_list=0; test_list<num_combo_cols; ++test_list)
9780 {
9781 if((x>=combolist[test_list].x) && (x<combolist[test_list].x+(combolist[test_list].xscale*combolist[test_list].w)))
9782 {
9783 break;
9784 }
9785 }
9786
9787 if(test_list<num_combo_cols)
9788 {
9789 if(y>=combolist[test_list].y-mouse_scroll_h && y<=combolist[test_list].y && First[test_list])
9790 {
9791 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9792 {
9793 First[test_list]=0;
9794 }
9795 else if(CHECK_CTRL_CMD)
9796 {
9797 First[test_list]-=zc_min(First[test_list],256);
9798 }
9799 else if(key[KEY_ALT] || key[KEY_ALTGR])
9800 {
9801 First[test_list]-=zc_min(First[test_list],(combolist[test_list].w*combolist[test_list].h));
9802 }
9803 else
9804 {
9805 First[test_list]-=zc_min(First[test_list],combolist[test_list].w);
9806 }
9807 }
9808
9809 if(y>=combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)-1 && y<combolist[test_list].y+(combolist[test_list].h*combolist[test_list].yscale)+mouse_scroll_h-1 && First[test_list]<(MAXCOMBOS-(combolist[test_list].w*combolist[test_list].h)))
9810 {
9811 int32_t offset = combolist[test_list].w*combolist[test_list].h;
9812
9813 if((CHECK_CTRL_CMD)&&(key[KEY_ALT] || key[KEY_ALTGR]))
9814 {
9815 First[test_list]=MAXCOMBOS-offset;
9816 }
9817 else if(CHECK_CTRL_CMD)
9818 {
9819 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+256);
9820 }
9821 else if(key[KEY_ALT] || key[KEY_ALTGR])
9822 {
9823 First[test_list] = zc_min(MAXCOMBOS-offset, First[test_list]+ offset);
9824 }
9825 else
9826 {
9827 First[test_list] = zc_min(MAXCOMBOS - offset, First[test_list] + combolist[test_list].w);
9828 }
9829 }
9830 }
9831 }
9832
9833 // The screen for this combo_pos, layer 0. Used to access ffcs.
9834 mapscr* scr = Map.Scr(combo_pos);
9835 // The screen for this combo_pos at the CurrentLayer. Could be same as scr.
9836 mapscr* draw_mapscr = scr && CurrentLayer ? Map.Scr(combo_pos, CurrentLayer) : scr;
9837 int c = combo_pos.truncate();
9838 set_active_visible_screen(scr);
9839
9840 //-------------
9841 //tooltip stuff
9842 //-------------
9843 if (active_visible_screen && isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
9844 {
9845 static int mapscr_tooltip_id = ttip_register_id();
9846 bool did_ffttip = false;
9847 int num_ffcs = scr->numFFC();
9848 for(int32_t i=num_ffcs-1; i>=0; i--)
9849 if(scr->ffcs[i].data !=0 && (CurrentLayer<2 || (scr->ffcs[i].flags&ffc_overlay)))
9850 {
9851 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
9852 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
9853 int32_t ffw = scr->ffTileWidth(i)*16;
9854 int32_t ffh = scr->ffTileHeight(i)*16;
9855 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
9856 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
9857
9858 if(cx2 >= ffx && cx2 < ffx+ffw && cy2 >= ffy && cy2 < ffy+ffh)
9859 {
9860 // FFC tooltip
9861 if(tooltip_current_ffc != i)
9862 {
9863 clear_tooltip();
9864 }
9865
9866 tooltip_current_ffc = i;
9867 char msg[1024] = {0};
9868 auto& ff = scr->ffcs[i];
9869 sprintf(msg,"FFC: %d Combo: %d\nCSet: %d Type: %s\nScript: %s",
9870 i+1, ff.data,ff.data,
9871 combo_class_buf[combobuf[ff.data].type].name,
9872 (ff.script<=0 ? "(None)" : ffcmap[ff.script-1].scriptname.substr(0,400).c_str()));
9873 ttip_install(mapscr_tooltip_id, msg, startxint+(ffx*mapscreen_single_scale), startyint+(ffy*mapscreen_single_scale), ffw*mapscreen_single_scale, ffh*mapscreen_single_scale, x, y);
9874 did_ffttip = true;
9875 break;
9876 }
9877 }
9878 if(!did_ffttip)
9879 {
9880 if(unsigned(c) < 176 && draw_mapscr && !gui_mouse_b())
9881 {
9882 int cid = draw_mapscr->data[c];
9883 newcombo const& cmb = combobuf[cid];
9884 std::ostringstream oss;
9885 int cs = draw_mapscr->cset[c];
9886 int sflag = draw_mapscr->sflag[c];
9887 oss << "Pos: " << c
9888 << "\nCombo: " << cid
9889 << "\nCSet: " << cs;
9890 if(sflag || cmb.flag)
9891 oss << "\nFlags: " << sflag << ", " << (int)cmb.flag;
9892 if(cmb.type)
9893 oss << "\nCombo type: " << combo_class_buf[cmb.type].name;
9894 if(cmb.label[0])
9895 oss << "\nLabel: " << cmb.label;
9896 ttip_install(mapscr_tooltip_id, oss.str().c_str(), startxint+(cx*16*mapscreen_single_scale), startyint+(cy*16*mapscreen_single_scale), 16*mapscreen_single_scale, 16*mapscreen_single_scale, x, y);
9897 }
9898 }
9899 }
9900
9901 {
9902 size_and_pos* squares[4] = {&itemsqr_pos,&stairsqr_pos,&warparrival_pos,&flagsqr_pos};
9903 for(int32_t j=0; j<4; j++)
9904 {
9905 auto& square = *squares[j];
9906 if(square.rect(x,y))
9907 {
9908 char msg[160];
9909 sprintf(msg,
9910 j==0 ? "Item Location" :
9911 j==1 ? "Stairs Secret\nTriggered when a Trigger Push Block is pushed." :
9912 j==2 ? "Arrival Square\nPlayer's location when they begin/resume the game." :
9913 "Combo Flags");
9914 update_tooltip(x,y,square,msg);
9915 }
9916 }
9917
9918 // Warp Returns
9919 for(int32_t j=0; j<4; j++)
9920 {
9921 size_and_pos& wret = warpret_pos[j];
9922 if(wret.rect(x,y))
9923 {
9924 char msg[160];
9925 sprintf(msg,"Warp Return Square %c\nPlayer's destination after warping to this screen.",(char)('A'+j));
9926 update_tooltip(x,y,wret,msg);
9927 }
9928 }
9929
9930 // Enemies
9931 if(enemy_prev_pos.rect(x,y))
9932 {
9933 char msg[160];
9934 sprintf(msg,"Enemies that appear on this screen.");
9935 update_tooltip(x,y,enemy_prev_pos,msg);
9936 }
9937
9938 int32_t cmd = commands_list.rectind(x,y);
9939 if(cmd > -1)
9940 {
9941 update_tooltip(x,y,commands_list.subsquare(cmd),
9942 fmt::format("Fav Command {}: {}\n{}", cmd,
9943 get_hotkey_name(favorite_commands[cmd]),
9944 get_hotkey_helptext(favorite_commands[cmd])).c_str());
9945 }
9946 }
9947
9948 if(draw_mode==dm_alias)
9949 {
9950 for(int32_t j=0; j<num_combo_cols; ++j)
9951 {
9952 auto& sqr = comboaliaslist[j];
9953 auto ind = sqr.rectind(x,y);
9954 if(ind > -1)
9955 {
9956 auto c2=ind+combo_alistpos[j];
9957 char msg[80];
9958 sprintf(msg, "Combo alias %d", c2);
9959 update_tooltip(x,y,sqr.subsquare(ind), msg);
9960 }
9961 }
9962 }
9963 else if(draw_mode==dm_cpool)
9964 {
9965 for(int32_t j=0; j<num_combo_cols; ++j)
9966 {
9967 auto& sqr = comboaliaslist[j];
9968 auto ind = sqr.rectind(x,y);
9969 if(ind > -1)
9970 {
9971 auto c2=ind+combo_pool_listpos[j];
9972 char msg[80];
9973 sprintf(msg, "Combo Pool %d", c2);
9974 update_tooltip(x,y,sqr.subsquare(ind), msg);
9975 }
9976 }
9977 if(cpool_prev_visible && combopool_prevbtn.rect(x,y))
9978 {
9979 if(do_layer_button_reset(combopool_prevbtn.x,combopool_prevbtn.y,
9980 combopool_prevbtn.w,combopool_prevbtn.h,
9981 weighted_cpool ? "Weighted" : "Unweighted",0,true))
9982 {
9983 weighted_cpool = !weighted_cpool;
9984 }
9985 }
9986 }
9987 else if (draw_mode == dm_auto)
9988 {
9989 for (int32_t j = 0; j < num_combo_cols; ++j)
9990 {
9991 auto& sqr = comboaliaslist[j];
9992 auto ind = sqr.rectind(x, y);
9993 if (ind > -1)
9994 {
9995 auto c2 = ind + combo_auto_listpos[j];
9996 char msg[80];
9997 sprintf(msg, "Auto Combo %d", c2);
9998 update_tooltip(x, y, sqr.subsquare(ind), msg);
9999 }
10000 }
10001 }
10002 else
10003 {
10004 if(combo_preview.rect(x,y))
10005 {
10006 auto str = "Combo Colors:\n"+get_combo_colornames(Combo,CSet);
10007 update_tooltip(x,y,combo_preview,str.c_str());
10008 }
10009 else if(comboprev_buf[0] && combo_preview_text1.rect(x,y))
10010 {
10011 update_tooltip(x,y,combo_preview_text1,comboprev_buf);
10012 }
10013 else if(comboprev_buf2[0] && combo_preview_text2.rect(x,y))
10014 {
10015 update_tooltip(x,y,combo_preview_text2,comboprev_buf2);
10016 }
10017 else for(int32_t j=0; j<num_combo_cols; ++j)
10018 {
10019 auto& sqr = combolist[j];
10020 auto ind = sqr.rectind(x,y);
10021 if(ind > -1)
10022 {
10023 int32_t c2=ind+First[j];
10024 std::ostringstream oss;
10025 newcombo const& cmb = combobuf[c2];
10026 oss << "Combo " << c2 << ": " << combo_class_buf[cmb.type].name;
10027 if(cmb.flag != 0)
10028 oss << "\nInherent flag: " << ZI.getMapFlagName(cmb.flag);
10029 if(!cmb.label.empty())
10030 oss << "\nLabel: " << cmb.label;
10031
10032 update_tooltip(x,y,sqr.subsquare(ind), oss.str().c_str());
10033 }
10034 }
10035 }
10036
10037 if (favorites_list.rect(x, y))
10038 {
10039 int32_t f = favorites_list.rectind(x, y);
10040 int32_t row = f / favorites_list.w;
10041 int32_t col = f % favorites_list.w;
10042 f = (row * FAVORITECOMBO_PER_ROW) + col;
10043
10044 auto& sqr = favorites_list.subsquare(col, row);
10045
10046 char buf[180];
10047 if (favorite_combos[f] == -1)
10048 sprintf(buf, "Fav Combo %d\nEmpty", f);
10049 else
10050 {
10051 switch (favorite_combo_modes[f])
10052 {
10053 case dm_alias:
10054 sprintf(buf, "Fav Combo %d\nAlias %d", f, favorite_combos[f]);
10055 break;
10056 case dm_cpool:
10057 sprintf(buf, "Fav Combo %d\nPool %d", f, favorite_combos[f]);
10058 break;
10059 case dm_auto:
10060 sprintf(buf, "Fav Combo %d\nAutocombo %d", f, favorite_combos[f]);
10061 break;
10062 default:
10063 sprintf(buf, "Fav Combo %d\nCombo %d", f, favorite_combos[f]);
10064 }
10065 }
10066 update_tooltip(x, y, sqr, buf);
10067 }
10068
10069 size_and_pos const& real_mini = zoomed_minimap ? real_minimap_zoomed : real_minimap;
10070 auto ind = real_mini.rectind(x,y);
10071 if(ind > -1)
10072 {
10073 char buf[80];
10074 sprintf(buf,"0x%02X (%d)", ind, ind);
10075 ttip_install(minimap_tooltip_id, buf, real_mini.subsquare(ind), real_mini.x+real_mini.tw(), real_mini.y-16);
10076 ttip_set_highlight_thickness(minimap_tooltip_id, zoomed_minimap ? 2 : 1);
10077 // Make sure always above the other tooltip items to the right of the map (even in big map mode).
10078 ttip_set_z_index(minimap_tooltip_id, 100);
10079 ttip_clear_timer();
10080 }
10081 else
10082 {
10083 ttip_uninstall(minimap_tooltip_id);
10084 }
10085
10086 // Mouse clicking stuff
10087 int real_mb = gui_mouse_b();
10088 int mb = real_mb & ~mouse_down; //Only handle clicks that have not been handled already
10089 auto mz = mouse_z;
10090 bool lclick = mb&1;
10091 bool rclick = mb&2;
10092
10093 if (mb && hotkeys_is_active())
10094 {
10095 hotkeys_toggle_display(false);
10096 while (gui_mouse_b())
10097 {
10098 custom_vsync();
10099 }
10100 return;
10101 }
10102
10103 FONT* tfont = font;
10104 if(zoomed_minimap)
10105 {
10106 if((lclick||rclick) && !minimap_zoomed.rect(x,y))
10107 {
10108 // 'Clicked off'
10109 mmap_set_zoom(false);
10110 goto domouse_doneclick;
10111 }
10112 }
10113
10114 if(real_mb==0)
10115 {
10116 mouse_down = 0;
10117 canfill=true;
10118 }
10119 else if(lclick || rclick)
10120 {
10121 //on the minimap
10122 if(real_mini.rect(x,y))
10123 {
10124 if(lclick)
10125 select_scr();
10126 else if(rclick && !(mouse_down&2))
10127 {
10128 mmap_set_zoom(!zoomed_minimap);
10129 }
10130 goto domouse_doneclick;
10131 }
10132
10133 if(zoomed_minimap && minimap_zoomed.rect(x,y))
10134 goto domouse_doneclick; //Eat clicks
10135
10136 //on the map tabs
10137 font = get_custom_font(CFONT_GUI);
10138 for(int32_t btn=0; btn<mappage_count; ++btn)
10139 {
10140 char tbuf[15];
10141 sprintf(tbuf, "%d:%02X", map_page[btn].map+1, map_page[btn].screen);
10142 auto& sqr = map_page_bar[btn];
10143 if(sqr.rect(x,y))
10144 {
10145 if(do_layer_button_reset(sqr.x,sqr.y,sqr.w,sqr.h,tbuf,(btn==current_mappage?D_SELECTED:0)))
10146 {
10147 draw_layer_button(screen, sqr.x,sqr.y,sqr.w,sqr.h,tbuf,D_SELECTED);
10148 map_page[current_mappage].map=Map.getCurrMap();
10149 map_page[current_mappage].screen=Map.getCurrScr();
10150 current_mappage=btn;
10151 Map.setCurrMap(map_page[current_mappage].map);
10152 Map.setCurrScr(map_page[current_mappage].screen);
10153 rebuild_trans_table(); //Woo
10154 }
10155 goto domouse_doneclick;
10156 }
10157 }
10158
10159 if(compactbtn.rect(x,y))
10160 {
10161 if(do_text_button(compactbtn.x, compactbtn.y, compactbtn.w, compactbtn.h, is_compact ? "< Expand" : "> Compact"));
10162 toggle_is_compact();
10163 goto domouse_doneclick;
10164 }
10165
10166 if(!zoom_in_btn_disabled && zoominbtn.rect(x,y))
10167 {
10168 if(do_text_button(zoominbtn.x, zoominbtn.y, zoominbtn.w, zoominbtn.h, "+"))
10169 change_mapscr_zoom(-1);
10170 goto domouse_doneclick;
10171 }
10172
10173 if(!zoom_out_btn_disabled && zoomoutbtn.rect(x,y))
10174 {
10175 if(do_text_button(zoomoutbtn.x, zoomoutbtn.y, zoomoutbtn.w, zoomoutbtn.h, "-"))
10176 change_mapscr_zoom(1);
10177 goto domouse_doneclick;
10178 }
10179
10180 font = get_zc_font(font_lfont_l);
10181 if(combo_merge_btn.rect(x,y))
10182 {
10183 bool merged = is_compact ? compact_merged_combopane : large_merged_combopane;
10184 if(do_text_button(combo_merge_btn.x,combo_merge_btn.y,combo_merge_btn.w,combo_merge_btn.h,merged ? "<|>" : ">|<"))
10185 {
10186 toggle_merged_mode();
10187 }
10188 goto domouse_doneclick;
10189 }
10190
10191 if(favorites_zoombtn.rect(x,y))
10192 {
10193 bool zoomed = is_compact ? compact_zoomed_fav : large_zoomed_fav;
10194 if(do_text_button(favorites_zoombtn.x,favorites_zoombtn.y,favorites_zoombtn.w,favorites_zoombtn.h,zoomed ? "-" : "+"))
10195 {
10196 toggle_favzoom_mode();
10197 }
10198 goto domouse_doneclick;
10199 }
10200 else if(favorites_x.rect(x,y))
10201 {
10202 if(do_text_button(favorites_x.x,favorites_x.y,favorites_x.w,favorites_x.h,"X"))
10203 {
10204 AlertDialog("Clear Favorite Combos",
10205 "Are you sure you want to clear all favorite combos?",
10206 [&](bool ret,bool)
10207 {
10208 if(ret)
10209 {
10210 for(auto q = 0; q < MAXFAVORITECOMBOS; ++q)
10211 {
10212 favorite_combos[q] = -1;
10213 favorite_combo_modes[q] = dm_normal;
10214 }
10215 saved = false;
10216 refresh(rFAVORITES);
10217 }
10218 }).show();
10219 }
10220 goto domouse_doneclick;
10221 }
10222 else if(favorites_infobtn.rect(x,y))
10223 {
10224 if(do_text_button(favorites_infobtn.x,favorites_infobtn.y,favorites_infobtn.w,favorites_infobtn.h,"?"))
10225 {
10226 InfoDialog("Favorite Combos",
10227 "On LClick (empty): Sets clicked favorite to the current combo."
10228 "\nOn LClick: Sets current combo to clicked favorite."
10229 "\nShift+LClick: Sets clicked favorite to current combo."
10230 "\nCtrl+LClick: Clears clicked favorite."
10231 "\nAlt+LClick: Scrolls to clicked favorite."
10232 "\nRClick: Opens context menu."
10233 "\n\nClick the Page buttons (<-/->) to cycle between pages (RClick to jump to a page)"
10234 "\nClick the Zoom button (+/-) to toggle zoom level."
10235 "\nClick the X button to clear all favorite combos.").show();
10236 }
10237 goto domouse_doneclick;
10238 }
10239 else if(favorites_pgleft.rect(x,y))
10240 {
10241 if (do_text_button(favorites_pgleft.x, favorites_pgleft.y, favorites_pgleft.w, favorites_pgleft.h, is_compact ? "<" : "<-"))
10242 {
10243 if (rclick)
10244 {
10245 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10246 FavoriteComboPage = vbound(*val-1, 0, 8);
10247 }
10248 else
10249 FavoriteComboPage = FavoriteComboPage == 0 ? 8 : --FavoriteComboPage;
10250 reload_zq_gui();
10251 }
10252 goto domouse_doneclick;
10253 }
10254 else if(favorites_pgright.rect(x,y))
10255 {
10256 if (do_text_button(favorites_pgright.x, favorites_pgright.y, favorites_pgright.w, favorites_pgright.h, is_compact ? ">" : "->"))
10257 {
10258 if (rclick)
10259 {
10260 if(auto val = popup_num_menu(x, y, 1, 9, FavoriteComboPage, [](int p){return fmt::format("Page {}",p);}))
10261 FavoriteComboPage = vbound(*val-1, 0, 8);
10262 }
10263 else
10264 FavoriteComboPage = FavoriteComboPage == 8 ? 0 : ++FavoriteComboPage;
10265 reload_zq_gui();
10266 }
10267 goto domouse_doneclick;
10268 }
10269
10270 if(commands_zoombtn.rect(x,y))
10271 {
10272 bool zoomed = is_compact ? compact_zoomed_cmd : large_zoomed_cmd;
10273 if(do_text_button(commands_zoombtn.x,commands_zoombtn.y,commands_zoombtn.w,commands_zoombtn.h,zoomed ? "-" : "+"))
10274 {
10275 toggle_cmdzoom_mode();
10276 }
10277 goto domouse_doneclick;
10278 }
10279 else if(commands_x.rect(x,y))
10280 {
10281 if(do_text_button(commands_x.x,commands_x.y,commands_x.w,commands_x.h,"X"))
10282 {
10283 AlertDialog("Clear Favorite Commands",
10284 "Are you sure you want to clear all favorite commands?",
10285 [&](bool ret,bool)
10286 {
10287 if(ret)
10288 {
10289 char buf[20];
10290 for(auto q = 0; q < MAXFAVORITECOMMANDS; ++q)
10291 {
10292 write_fav_command(q,0);
10293 }
10294 refresh(rFAVORITES);
10295 }
10296 }).show();
10297 }
10298 goto domouse_doneclick;
10299 }
10300 else if(commands_infobtn.rect(x,y))
10301 {
10302 if(do_text_button(commands_infobtn.x,commands_infobtn.y,commands_infobtn.w,commands_infobtn.h,"?"))
10303 {
10304 InfoDialog("Favorite Commands",
10305 "On LClick (empty): Choose a favorite command"
10306 "\nOn LClick: Runs the favorite command"
10307 "\nShift+Click: Choose a favorite command"
10308 "\nRClick: Choose a favorite command"
10309 "\nCtrl+Click: Clears clicked command"
10310 "\nAlt+Click: Shows info on the favorite command"
10311 "\n\nClick the Zoom button (+/-) to toggle zoom level"
10312 "\nClick the X button to clear all favorite commands").show();
10313 }
10314 goto domouse_doneclick;
10315 }
10316 font=tfont;
10317
10318 // On the layer panel
10319 font = get_custom_font(CFONT_GUI);
10320 for(int32_t i=0; i<=6; ++i)
10321 {
10322 int32_t spacing_offs = is_compact ? 2 : 10;
10323 int32_t rx = (i * (layerpanel_buttonwidth+spacing_offs+layerpanel_checkbox_wid)) + layer_panel.x+(is_compact?2:6);
10324 int32_t ry = layer_panel.y;
10325
10326 if ((i == 0 || mapscreen_valid_layers[i - 1]) && isinRect(x,y,rx,ry,rx+layerpanel_buttonwidth-1,ry+layerpanel_buttonheight-1))
10327 {
10328 char tbuf[15];
10329
10330 if (Map.getViewSize() > 1)
10331 {
10332 sprintf(tbuf, "%d", i);
10333 }
10334 else if (i != 0 && mapscreen_valid_layers[i - 1])
10335 {
10336 if (is_compact)
10337 {
10338 sprintf(tbuf, "%s%d %d:%02X",
10339 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10340 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10341 }
10342 else
10343 {
10344 sprintf(tbuf, "%s%d (%d:%02X)",
10345 (i==2 && Map.CurrScr()->flags7&fLAYER2BG) || (i==3 && Map.CurrScr()->flags7&fLAYER3BG) ? "-":"",
10346 i, Map.CurrScr()->layermap[i-1], Map.CurrScr()->layerscreen[i-1]);
10347 }
10348 }
10349 else
10350 {
10351 sprintf(tbuf, "%d", i);
10352 }
10353
10354 if(do_text_button(rx, ry, layerpanel_buttonwidth, layerpanel_buttonheight, tbuf))
10355 {
10356 CurrentLayer = i;
10357 goto domouse_doneclick;
10358 }
10359 }
10360
10361 auto cbyofs = (layerpanel_buttonheight-layerpanel_checkbox_hei)/2;
10362 if(isinRect(x,y,rx+layerpanel_buttonwidth+1,ry+cbyofs,rx+layerpanel_buttonwidth+1+layerpanel_checkbox_wid-1,ry+2+layerpanel_checkbox_hei-1))
10363 {
10364 do_checkbox(menu1,rx+layerpanel_buttonwidth+1,ry+cbyofs,layerpanel_checkbox_wid,layerpanel_checkbox_hei,LayerMaskInt[i]);
10365 goto domouse_doneclick;
10366 }
10367 }
10368 font=tfont;
10369
10370 //Uses lclick/rclick separately
10371
10372 //on the map screen
10373 if(isinRect(x,y,startxint,startyint,startxint+(256*mapscreen_screenunit_scale)-1,startyint+(176*mapscreen_screenunit_scale)-1))
10374 {
10375 if (lclick)
10376 {
10377 Map.setCurrScr(Map.getScreenForPosition(combo_pos));
10378 }
10379
10380 if (draw_mode == dm_auto)
10381 {
10382 if (CHECK_CTRL_CMD)
10383 {
10384 if (canfill)
10385 {
10386 switch (fill_type)
10387 {
10388 case 0:
10389 flood();
10390 break;
10391
10392 case 1:
10393 fill_4();
10394 break;
10395
10396 case 2:
10397 fill_8();
10398 break;
10399
10400 case 3:
10401 fill2_4();
10402 break;
10403
10404 case 4:
10405 fill2_8();
10406 break;
10407 }
10408
10409 canfill = false;
10410 }
10411 }
10412 else
10413 draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10414 }
10415 else if (scr && lclick)
10416 {
10417 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10418 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10419
10420 // Move items
10421 if (scr->hasitem && active_visible_screen)
10422 {
10423 int32_t ix = scr->itemx + active_visible_screen->dx * 256;
10424 int32_t iy = scr->itemy + active_visible_screen->dy * 176;
10425
10426 if(cx2 >= ix && cx2 < ix+16 && cy2 >= iy && cy2 < iy+16)
10427 doxypos(scr->itemx, scr->itemy, 11, SNAP_HALF, SNAP_NONE, true, 0, 0, 16, 16);
10428 }
10429
10430 // Move FFCs
10431 int num_ffcs = scr->numFFC();
10432 for(int32_t i=num_ffcs-1; i>=0; i--)
10433 if(scr->ffcs[i].data !=0 && (CurrentLayer<2 || (scr->ffcs[i].flags&ffc_overlay)))
10434 {
10435 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10436 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10437
10438 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10439 {
10440 moveffc(i, cx2, cy2);
10441 break;
10442 }
10443 }
10444
10445 if(key[KEY_ALT]||key[KEY_ALTGR])
10446 {
10447 if (!draw_mapscr) return;
10448
10449 Combo=draw_mapscr->data[c];
10450 if(AutoBrush)
10451 BrushWidth = BrushHeight = 1;
10452 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
10453 CSet=draw_mapscr->cset[c];
10454 if(CHECK_CTRL_CMD)
10455 First[current_combolist]=scrollto_cmb(draw_mapscr->data[c]);
10456 }
10457 else if(CHECK_CTRL_CMD)
10458 {
10459 if(canfill)
10460 {
10461 switch(fill_type)
10462 {
10463 case 0:
10464 flood();
10465 break;
10466
10467 case 1:
10468 fill_4();
10469 break;
10470
10471 case 2:
10472 fill_8();
10473 break;
10474
10475 case 3:
10476 fill2_4();
10477 break;
10478
10479 case 4:
10480 fill2_8();
10481 break;
10482 }
10483
10484 canfill=false;
10485 }
10486 }
10487 else draw(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10488 }
10489 else if (scr && rclick)
10490 {
10491 ComboBrushPause=1;
10492 refresh(rMAP);
10493 restore_mouse();
10494 ComboBrushPause=0;
10495
10496 bool clickedffc = false;
10497
10498 // FFC right-click menu
10499 // This loop also serves to find the free ffc with the smallest slot number.
10500 int num_ffcs = scr->numFFC();
10501 uint32_t earliestfreeffc = num_ffcs;
10502 for(int32_t i=num_ffcs-1; i>=0; i--)
10503 {
10504 auto data = scr->ffcs[i].data;
10505 if(data==0)
10506 {
10507 if(i < earliestfreeffc)
10508 earliestfreeffc = i;
10509 continue;
10510 }
10511
10512 if(clickedffc || !(scr->valid&mVALID))
10513 continue;
10514
10515 if(data!=0 && (CurrentLayer<2 || (scr->ffcs[i].flags&ffc_overlay)))
10516 {
10517 int32_t ffx = scr->ffcs[i].x.getFloor() + active_visible_screen->dx * 256;
10518 int32_t ffy = scr->ffcs[i].y.getFloor() + active_visible_screen->dy * 176;
10519 int32_t cx2 = (x-startxint)/mapscreen_single_scale;
10520 int32_t cy2 = (y-startyint)/mapscreen_single_scale;
10521
10522 if(cx2 >= ffx && cx2 < ffx+(scr->ffTileWidth(i)*16) && cy2 >= ffy && cy2 < ffy+(scr->ffTileHeight(i)*16))
10523 {
10524 NewMenu rcmenu
10525 {
10526 { "Copy FFC", [&](){Map.CopyFFC(active_visible_screen->screen, i);} },
10527 { "Paste FFC data", [&]()
10528 {
10529 bool didconfirm = false;
10530 AlertDialog("Confirm Paste",
10531 "Really replace the FFC with the data of the copied FFC?",
10532 [&](bool ret,bool)
10533 {
10534 if(ret)
10535 didconfirm = true;
10536 }).show();
10537 if(didconfirm)
10538 {
10539 auto set_ffc_data = Map.getCopyFFCData();
10540 set_ffc_data.x = scr->ffcs[i].x;
10541 set_ffc_data.y = scr->ffcs[i].y;
10542 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10543 }
10544 }, nullopt, Map.getCopyFFC() < 0 },
10545 { "Edit FFC", [&](){call_ffc_dialog(i, active_visible_screen->scr, active_visible_screen->screen);} },
10546 { "Clear FFC", [&]()
10547 {
10548 bool didconfirm = false;
10549 AlertDialog("Confirm Clear",
10550 "Really clear this Freeform Combo?",
10551 [&](bool ret,bool)
10552 {
10553 if(ret)
10554 didconfirm = true;
10555 }).show();
10556 if(didconfirm)
10557 {
10558 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, {
10559 .x = 0,
10560 .y = 0,
10561 .vx = 0,
10562 .vy = 0,
10563 .ax = 0,
10564 .ay = 0,
10565 .data = 0,
10566 .cset = 0,
10567 .delay = 0,
10568 .link = 0,
10569 .script = 0,
10570 .tw = 1,
10571 .th = 1,
10572 .ew = 16,
10573 .eh = 16,
10574 .flags = ffc_none,
10575 .initd = 0,
10576 });
10577 saved = false;
10578 }
10579 } },
10580 { "Snap to Grid", [&]()
10581 {
10582 int oldffx = scr->ffcs[i].x.getInt();
10583 int oldffy = scr->ffcs[i].y.getInt();
10584 int pos = COMBOPOS(oldffx,oldffy);
10585 int newffy = COMBOY(pos);
10586 int newffx = COMBOX(pos);
10587
10588 auto set_ffc_data = set_ffc_command::create_data(scr->ffcs[i]);
10589 set_ffc_data.x = newffx;
10590 set_ffc_data.y = newffy;
10591 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, i, set_ffc_data);
10592
10593 saved = false;
10594 } },
10595 };
10596 rcmenu.pop(x, y);
10597 clickedffc = true;
10598 break;
10599 }
10600 }
10601 }
10602
10603 // Combo right-click menu
10604 if(!clickedffc)
10605 {
10606 int warpindex = Map.warpindex(scr->data[c]);
10607 string txt_twarp_follow, txt_twarp_edit, txt_ffc_edit, txt_ffc_paste;
10608 bool show_ffcs = earliestfreeffc < MAXFFCS;
10609 bool dis_paste_ffc = Map.getCopyFFC() < 0;
10610 bool show_warps = warpindex > -1;
10611 bool show_warpback = Map.has_warpback();
10612 // FFC-specific options
10613 if(earliestfreeffc < MAXFFCS)
10614 {
10615 txt_ffc_edit = fmt::format("Edit New FFC {}",earliestfreeffc+1);
10616 if(Map.getCopyFFC()>-1)
10617 txt_ffc_paste = fmt::format("Paste FFC as FFC {}",earliestfreeffc+1);
10618 else
10619 txt_ffc_paste = "Paste FFC";
10620 }
10621
10622 if(warpindex > -1)
10623 {
10624 char letter = warpindex==4 ? 'R' : 'A'+warpindex;
10625 txt_twarp_follow = fmt::format("Follow Tile Warp {}",letter);
10626 txt_twarp_edit = fmt::format("Edit Tile Warp {}",letter);
10627 }
10628
10629 NewMenu draw_rc_menu
10630 {
10631 { "Select Combo", [&]()
10632 {
10633 Combo = draw_mapscr->data[c];
10634 if(AutoBrush)
10635 BrushWidth = BrushHeight = 1;
10636 }, nullopt, !draw_mapscr },
10637 { "Scroll to Combo", [&]()
10638 {
10639 First[current_combolist] = scrollto_cmb(draw_mapscr->data[c]);
10640 }, nullopt, !draw_mapscr },
10641 { "Edit Combo", [&]()
10642 {
10643 edit_combo(draw_mapscr->data[c],true,draw_mapscr->cset[c]);
10644 }, nullopt, !draw_mapscr },
10645 {},
10646 { "Replace All", [&](){replace(combo_pos);} },
10647 { "Draw Block", &draw_block_menu },
10648 { "Brush Settings ", &brush_menu },
10649 { "Set Fill Type ", &fill_menu },
10650 };
10651 if(show_warps || show_warpback)
10652 {
10653 draw_rc_menu.add_sep();
10654 if(show_warpback)
10655 draw_rc_menu.add({ "Warp Back", [&](){Map.warpback();} });
10656 if(show_warps)
10657 {
10658 draw_rc_menu.add({ txt_twarp_follow, [&](){follow_twarp(warpindex);} });
10659 draw_rc_menu.add({ txt_twarp_edit, [&](){edit_twarp(warpindex);} });
10660 }
10661 }
10662 if(show_ffcs)
10663 {
10664 draw_rc_menu.add_sep();
10665 draw_rc_menu.add({ txt_ffc_edit, [&]()
10666 {
10667 ffdata tempdat;
10668 // x, y are ints on ffdata (but ffc x, y are zfix), so *10000
10669 tempdat.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256) * 10000;
10670 tempdat.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176) * 10000;
10671 tempdat.data = Combo;
10672 tempdat.cset = CSet;
10673 call_ffc_dialog(earliestfreeffc, tempdat, active_visible_screen->scr, active_visible_screen->screen);
10674 } });
10675 draw_rc_menu.add({ txt_ffc_paste, [&]()
10676 {
10677 auto set_ffc_data = Map.getCopyFFCData();
10678 set_ffc_data.x = ((int((x-startxint)/mapscreen_single_scale)&(~0x0007)) % 256);
10679 set_ffc_data.y = ((int((y-startyint)/mapscreen_single_scale)&(~0x0007)) % 176);
10680 Map.DoSetFFCCommand(Map.getCurrMap(), active_visible_screen->screen, earliestfreeffc, set_ffc_data);
10681 }, nullopt, dis_paste_ffc });
10682 }
10683 draw_rc_menu.add_sep();
10684 draw_rc_menu.add({ "Screen", &rc_menu_screen });
10685 draw_rc_menu.pop(x,y);
10686 }
10687 }
10688 goto domouse_doneclick;
10689 }
10690
10691 //on the drawing mode button
10692 font = get_custom_font(CFONT_GUI);
10693 if(drawmode_btn.rect(x,y))
10694 {
10695 if(lclick)
10696 {
10697 if(do_text_button(drawmode_btn.x,drawmode_btn.y,drawmode_btn.w,drawmode_btn.h,dm_names[draw_mode]))
10698 onDrawingMode();
10699 }
10700 else if(rclick)
10701 drawing_mode_menu.pop(x,y);
10702 goto domouse_doneclick;
10703 }
10704 font=tfont;
10705
10706 //Squares
10707 //
10708 set_active_visible_screen(Map.CurrScr());
10709 {
10710 if(squarepanel_swap_btn.rect(x,y))
10711 {
10712 toggle_compact_sqr_mode();
10713 goto domouse_doneclick;
10714 }
10715 if(squarepanel_up_btn.rect(x,y))
10716 {
10717 cycle_compact_sqr(false);
10718 goto domouse_doneclick;
10719 }
10720 if(squarepanel_down_btn.rect(x,y))
10721 {
10722 cycle_compact_sqr(true);
10723 goto domouse_doneclick;
10724 }
10725
10726 bool do_dummyxy = false;
10727 bool dummymode = key[KEY_LSHIFT] || key[KEY_RSHIFT];
10728
10729 if(itemsqr_pos.rect(x,y))
10730 {
10731 if(dummymode) do_dummyxy = true;
10732 else
10733 {
10734 onItem();
10735
10736 if(!rclick && Map.CurrScr()->hasitem)
10737 doxypos(Map.CurrScr()->itemx,Map.CurrScr()->itemy,11,SNAP_HALF,SNAP_NONE);
10738 goto domouse_doneclick;
10739 }
10740 }
10741
10742 if(stairsqr_pos.rect(x,y))
10743 {
10744 if(dummymode) do_dummyxy = true;
10745 else
10746 {
10747 doxypos(Map.CurrScr()->stairx,Map.CurrScr()->stairy,14,SNAP_WHOLE);
10748 goto domouse_doneclick;
10749 }
10750 }
10751
10752 if(warparrival_pos.rect(x,y))
10753 {
10754 if(dummymode) do_dummyxy = true;
10755 else
10756 {
10757 if(get_qr(qr_NOARRIVALPOINT))
10758 {
10759 info_dsa("Arrival Square",
10760 "The arrival square cannot be used unless the QR 'Use Warp Return "
10761 "Points Only' under 'Quest->Options->Combos' is disabled."
10762 "\nGenerally, this square only exists for compatibility purposes, and is not used"
10763 " in creating new quests.",
10764 "dsa_warparrival");
10765 }
10766 else doxypos(Map.CurrScr()->warparrivalx,Map.CurrScr()->warparrivaly,10,SNAP_HALF,SNAP_NONE);
10767 goto domouse_doneclick;
10768 }
10769 }
10770
10771 if(flagsqr_pos.rect(x,y))
10772 {
10773 if(dummymode) do_dummyxy = true;
10774 else
10775 {
10776 onFlags();
10777 goto domouse_doneclick;
10778 }
10779 }
10780
10781 for(auto q = 0; q < 4; ++q)
10782 {
10783 if(warpret_pos[q].rect(x,y))
10784 {
10785 if(dummymode) do_dummyxy = true;
10786 else
10787 {
10788 doxypos(Map.CurrScr()->warpreturnx[q],Map.CurrScr()->warpreturny[q],9,SNAP_HALF,SNAP_NONE);
10789 goto domouse_doneclick;
10790 }
10791 }
10792 }
10793
10794 if(enemy_prev_pos.rect(x,y))
10795 {
10796 if(dummymode) do_dummyxy = true;
10797 else
10798 {
10799 onEnemies();
10800 goto domouse_doneclick;
10801 }
10802 }
10803
10804 if(do_dummyxy)
10805 {
10806 byte x = 0, y = 0;
10807 showxypos_dummy = true;
10808 doxypos(x,y,13,SNAP_HALF,SNAP_NONE);
10809 goto domouse_doneclick;
10810 }
10811 }
10812
10813 if(draw_mode==dm_alias)
10814 {
10815 for(int32_t j=0; j<num_combo_cols; ++j)
10816 {
10817 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10818 {
10819 scrollup(j);
10820 goto domouse_doneclick;
10821 }
10822 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10823 {
10824 scrolldown(j);
10825 goto domouse_doneclick;
10826 }
10827 else if(comboaliaslist[j].rect(x,y))
10828 {
10829 select_comboa(j);
10830
10831 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10832 popup_cpane_rc(x, y);
10833 goto domouse_doneclick;
10834 }
10835 }
10836 }
10837 else if(draw_mode==dm_cpool)
10838 {
10839 for(int32_t j=0; j<num_combo_cols; ++j)
10840 {
10841 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10842 {
10843 scrollup(j);
10844 goto domouse_doneclick;
10845 }
10846 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10847 {
10848 scrolldown(j);
10849 goto domouse_doneclick;
10850 }
10851 else if(comboaliaslist[j].rect(x,y))
10852 {
10853 select_combop(j);
10854
10855 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10856 popup_cpane_rc(x, y);
10857 goto domouse_doneclick;
10858 }
10859 }
10860 }
10861 else if (draw_mode == dm_auto)
10862 {
10863 for (int32_t j = 0; j < num_combo_cols; ++j)
10864 {
10865 if (combolistscrollers[j].rectind(x, y) == 0 && !mouse_down)
10866 {
10867 scrollup(j);
10868 goto domouse_doneclick;
10869 }
10870 else if (combolistscrollers[j].rectind(x, y) == 1 && !mouse_down)
10871 {
10872 scrolldown(j);
10873 goto domouse_doneclick;
10874 }
10875 else if (comboaliaslist[j].rect(x, y))
10876 {
10877 select_autocombo(j);
10878
10879 if(rclick && comboaliaslist[j].rect(gui_mouse_x(),gui_mouse_y()))
10880 popup_cpane_rc(x, y);
10881 goto domouse_doneclick;
10882 }
10883 }
10884 }
10885 else
10886 {
10887 for(int32_t j=0; j<num_combo_cols; ++j)
10888 {
10889 if(combolistscrollers[j].rectind(x,y)==0 && !mouse_down)
10890 {
10891 scrollup(j);
10892 goto domouse_doneclick;
10893 }
10894 else if(combolistscrollers[j].rectind(x,y)==1 && !mouse_down)
10895 {
10896 scrolldown(j);
10897 goto domouse_doneclick;
10898 }
10899 else if(combolist[j].rect(x,y))
10900 {
10901 select_combo(j);
10902
10903 if(rclick && combolist[j].rect(gui_mouse_x(),gui_mouse_y()))
10904 popup_cpane_rc(x, y);
10905 goto domouse_doneclick;
10906 }
10907 }
10908 }
10909
10910 //on the favorites list
10911 if(favorites_list.rect(x,y))
10912 {
10913 if(lclick)
10914 {
10915 int32_t f=favorites_list.rectind(x,y);
10916 int32_t row=f/favorites_list.w;
10917 int32_t col=f%favorites_list.w;
10918 f = (row*FAVORITECOMBO_PER_ROW)+col;
10919 int32_t fp = f + FAVORITECOMBO_PER_PAGE * FavoriteComboPage;
10920
10921 bool dmcond = favorite_combos[fp] < 0;
10922 if((key[KEY_LSHIFT] || key[KEY_RSHIFT] || dmcond) && !(CHECK_CTRL_CMD))
10923 {
10924 int32_t tempcb=ComboBrush;
10925 ComboBrush=0;
10926
10927 while(gui_mouse_b())
10928 {
10929 x=gui_mouse_x();
10930 y=gui_mouse_y();
10931
10932 switch(draw_mode)
10933 {
10934 case dm_alias:
10935 if (favorite_combos[fp] != combo_apos || favorite_combo_modes[fp] != dm_alias)
10936 {
10937 favorite_combo_modes[fp] = dm_alias;
10938 favorite_combos[fp] = combo_apos;
10939 saved = false;
10940 }
10941 break;
10942 case dm_cpool:
10943 if (favorite_combos[fp] != combo_pool_pos || favorite_combo_modes[fp] != dm_cpool)
10944 {
10945 favorite_combo_modes[fp] = dm_cpool;
10946 favorite_combos[fp] = combo_pool_pos;
10947 saved = false;
10948 }
10949 break;
10950 case dm_auto:
10951 if (favorite_combos[fp] != combo_auto_pos || favorite_combo_modes[fp] != dm_auto)
10952 {
10953 favorite_combo_modes[fp] = dm_auto;
10954 favorite_combos[fp] = combo_auto_pos;
10955 saved = false;
10956 }
10957 break;
10958 default:
10959 if (favorite_combos[fp] != Combo || favorite_combo_modes[fp] != dm_normal)
10960 {
10961 if (BrushWidth > 1 || BrushHeight > 1)
10962 {
10963 add_favorite_combo_block(f, Combo, key[KEY_LSHIFT] || key[KEY_RSHIFT]);
10964 break;
10965 }
10966 favorite_combo_modes[fp] = dm_normal;
10967 favorite_combos[fp] = Combo;
10968 saved = false;
10969 }
10970 }
10971
10972 custom_vsync();
10973 refresh(rALL | rFAVORITES);
10974 }
10975
10976 ComboBrush=tempcb;
10977 }
10978 else if(CHECK_CTRL_CMD)
10979 {
10980 int32_t tempcb=ComboBrush;
10981 ComboBrush=0;
10982
10983 while(gui_mouse_b())
10984 {
10985 x=gui_mouse_x();
10986 y=gui_mouse_y();
10987
10988 if(favorite_combos[fp]!=-1)
10989 {
10990 favorite_combo_modes[fp] = dm_normal;
10991 favorite_combos[fp]=-1;
10992 saved=false;
10993 }
10994
10995 custom_vsync();
10996 refresh(rALL | rFAVORITES);
10997 }
10998
10999 ComboBrush=tempcb;
11000 }
11001 else if(key[KEY_ALT] || key[KEY_ALTGR])
11002 {
11003 if(select_favorite())
11004 {
11005 switch(favorite_combo_modes[fp])
11006 {
11007 case dm_alias:
11008 combo_alistpos[current_comboalist]=scrollto_alias(combo_apos);
11009 break;
11010 case dm_cpool:
11011 combo_pool_listpos[current_cpoollist] = scrollto_cpool(combo_pool_pos);
11012 break;
11013 case dm_auto:
11014 combo_auto_listpos[current_cautolist] = scrollto_cauto(combo_auto_pos);
11015 break;
11016 default:
11017 First[current_combolist]=scrollto_cmb(Combo);
11018 }
11019 }
11020 }
11021 else
11022 {
11023 select_favorite();
11024 }
11025 }
11026 else if(rclick)
11027 {
11028 bool valid=select_favorite();
11029
11030 if(valid)
11031 {
11032 int f = favorites_list.rectind(x,y);
11033 int row = f/favorites_list.w;
11034 int col = f%favorites_list.w;
11035 f = (row*FAVORITECOMBO_PER_ROW) + col + (FAVORITECOMBO_PER_PAGE * FavoriteComboPage);
11036 popup_favorites_rc(f, x, y);
11037 }
11038 }
11039 goto domouse_doneclick;
11040 }
11041
11042 //on the commands buttons
11043 int32_t cmd = commands_list.rectind(x,y);
11044 if(cmd > -1)
11045 {
11046 uint hkey = favorite_commands[cmd];
11047 bool shift=(key[KEY_LSHIFT] || key[KEY_RSHIFT]);
11048 bool ctrl=(CHECK_CTRL_CMD);
11049 bool alt=(key[KEY_ALT] || key[KEY_ALTGR]);
11050 bool dis = disabled_hotkey(hkey);
11051 auto& btn = commands_list.subsquare(cmd);
11052 if(!dis||rclick||shift||ctrl||alt)
11053 {
11054 FONT *tfont=font;
11055 font=get_custom_font(CFONT_FAVCMD);
11056 if(do_layer_button_reset(btn.x,btn.y,btn.w,btn.h,
11057 get_hotkey_name(hkey),
11058 selected_hotkey(hkey)?D_SELECTED:0,
11059 true))
11060 {
11061 font=tfont;
11062 if(alt)
11063 {
11064 show_hotkey_info(hkey);
11065 }
11066 else if(ctrl)
11067 {
11068 write_fav_command(cmd,0);
11069 }
11070 else if(rclick || shift || hkey==ZQKEY_NULL_KEY)
11071 {
11072 if(auto newkey = select_fav_command())
11073 write_fav_command(cmd,*newkey);
11074 }
11075 else
11076 {
11077 run_hotkey(hkey);
11078 }
11079 }
11080
11081 font=tfont;
11082 }
11083 goto domouse_doneclick;
11084 }
11085 }
11086
11087 domouse_doneclick:
11088 mouse_down |= mb&3;
11089
11090 if(mouse_z!=0)
11091 {
11092 int32_t z=0;
11093
11094 for(int32_t j=0; j<num_combo_cols; ++j)
11095 {
11096 z=abs(mouse_z);
11097
11098 if(key[KEY_ALT]||key[KEY_ALTGR])
11099 {
11100 z*=combolist[j].h;
11101 }
11102
11103
11104 if(draw_mode == dm_alias)
11105 {
11106 if(comboaliaslist[j].rect(x,y))
11107 {
11108 if(mouse_z<0) //scroll down
11109 {
11110 combo_alistpos[current_comboalist] = zc_min(MAXCOMBOALIASES - comboaliaslist[j].w*comboaliaslist[j].h,
11111 combo_alistpos[current_comboalist]+comboaliaslist[j].w*z);
11112 }
11113 else //scroll up
11114 {
11115 if(combo_alistpos[current_comboalist]>0)
11116 {
11117 combo_alistpos[current_comboalist]-=zc_min(combo_alistpos[current_comboalist],comboaliaslist[j].w*z);
11118 }
11119 }
11120 goto domouse_donez;
11121 }
11122 }
11123 else if(draw_mode == dm_cpool)
11124 {
11125 if(comboaliaslist[j].rect(x,y))
11126 {
11127 if(mouse_z<0) //scroll down
11128 {
11129 combo_pool_listpos[current_cpoollist] = zc_min(MAXCOMBOPOOLS - comboaliaslist[j].w*comboaliaslist[j].h,
11130 combo_pool_listpos[current_cpoollist]+comboaliaslist[j].w*z);
11131 }
11132 else //scroll up
11133 {
11134 if(combo_pool_listpos[current_cpoollist]>0)
11135 {
11136 combo_pool_listpos[current_cpoollist]-=zc_min(combo_pool_listpos[current_cpoollist],comboaliaslist[j].w*z);
11137 }
11138 }
11139 goto domouse_donez;
11140 }
11141 }
11142 else if (draw_mode == dm_auto)
11143 {
11144 if (comboaliaslist[j].rect(x, y))
11145 {
11146 if (mouse_z < 0) //scroll down
11147 {
11148 combo_auto_listpos[current_cautolist] = zc_min(MAXAUTOCOMBOS - comboaliaslist[j].w * comboaliaslist[j].h,
11149 combo_auto_listpos[current_cautolist] + comboaliaslist[j].w * z);
11150 }
11151 else //scroll up
11152 {
11153 if (combo_auto_listpos[current_cautolist] > 0)
11154 {
11155 combo_auto_listpos[current_cautolist] -= zc_min(combo_auto_listpos[current_cautolist], comboaliaslist[j].w * z);
11156 }
11157 }
11158 goto domouse_donez;
11159 }
11160 }
11161 else
11162 {
11163 if(combolist[j].rect(x,y))
11164 {
11165 if(mouse_z<0) //scroll down
11166 {
11167 First[current_combolist] = zc_min(MAXCOMBOS-combolist[j].w*combolist[j].h,
11168 First[current_combolist] + combolist[j].w*z);
11169 }
11170 else //scroll up
11171 {
11172 if(First[current_combolist]>0)
11173 {
11174 First[current_combolist]-=zc_min(First[current_combolist],combolist[j].w*z);
11175 }
11176 }
11177 goto domouse_donez;
11178 }
11179 }
11180 }
11181
11182 z=abs(mouse_z);
11183
11184 if(real_mini.rect(x,y))
11185 {
11186 for(int32_t i=0; i<z; ++i)
11187 {
11188 if(mouse_z>0) onIncMap();
11189 else onDecMap();
11190 }
11191 goto domouse_donez;
11192 }
11193
11194 if(is_compact && compact_square_panels
11195 && squares_panel.rect(x,y))
11196 {
11197 cycle_compact_sqr(mouse_z < 0);
11198 goto domouse_donez;
11199 }
11200 domouse_donez:
11201 position_mouse_z(0);
11202 }
11203 font = tfont;
11204 active_visible_screen = nullptr;
11205 }
11206
11207 int32_t d_viewpal_proc(int32_t msg, DIALOG *d, int32_t c)
11208 {
11209 int32_t ret = d_bitmap_proc(msg, d, c);
11210 char* buf = (char*)d->dp2; //buffer to store the color code in
11211 DIALOG* d2 = (DIALOG*)d->dp3; //DIALOG* to update the text proc
11212 if(!buf)
11213 return ret;
11214 switch(msg)
11215 {
11216 case MSG_IDLE:
11217 case MSG_GOTMOUSE:
11218 case MSG_LOSTMOUSE:
11219 break;
11220 default:
11221 return ret;
11222 }
11223 char t[16];
11224 memcpy(t, buf, 16);
11225 int32_t x = gui_mouse_x() - d->x;
11226 int32_t y = gui_mouse_y() - d->y;
11227 if(msg != MSG_LOSTMOUSE && isinRect(x, y, 0, 0, d->w-1, d->h-1))
11228 {
11229 float palscale = 1.5;
11230 for(int32_t i = 0; i<256; ++i)
11231 if(isinRect(x,y,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale)))
11232 {
11233 sprintf(buf, "0x%02X (%03d) ", i, i); //Extra spaces to increase drawn width, so it draws the blank area
11234 break;
11235 }
11236 }
11237 else memset(buf, ' ', 15);
11238 if(strcmp(buf, t) && d2 && d2->proc == jwin_text_proc && d2->dp == d->dp2)
11239 object_message(d2, MSG_DRAW, 0);
11240 return ret;
11241 }
11242
11243 static DIALOG showpal_dlg[] =
11244 {
11245 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11246 { jwin_win_proc, 24, 68, 272, 119, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "View Palette", NULL, NULL },
11247 { jwin_frame_proc, 30, 76+16, 260, 68, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11248 { d_viewpal_proc, 32, 76+18, 256, 64, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11249 { jwin_text_proc, 32+8,76+18+66, 20, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
11250 { jwin_button_proc, 130, 144+18, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11251 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11252 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11253 };
11254
11255 int32_t onShowPal()
11256 {
11257 float palscale = 1.5;
11258
11259 BITMAP *palbmp = create_bitmap_ex(8,(int32_t)(256*palscale),(int32_t)(64*palscale));
11260
11261 if(!palbmp)
11262 return D_O_K;
11263 clear_to_color(palbmp,jwin_pal[jcBOX]); //If not cleared, random static appears between swatches! -E
11264 showpal_dlg[0].dp2=get_zc_font(font_lfont);
11265
11266 for(int32_t i=0; i<256; i++)
11267 rectfill(palbmp,(int32_t)(((i&31)<<3)*palscale),(int32_t)(((i&0xE0)>>2)*palscale), (int32_t)((((i&31)<<3)+7)*palscale),(int32_t)((((i&0xE0)>>2)+7)*palscale),i);
11268 showpal_dlg[2].dp=(void *)palbmp;
11269 char buf[16] = {0};
11270 showpal_dlg[2].dp2=(void *)buf;
11271 showpal_dlg[2].dp3=(void *)&(showpal_dlg[3]);
11272 showpal_dlg[3].dp=(void *)buf;
11273 showpal_dlg[3].dp2=(void *)get_zc_font(font_deffont);
11274
11275 large_dialog(showpal_dlg);
11276 do_zqdialog(showpal_dlg,2);
11277 destroy_bitmap(palbmp);
11278 return D_O_K;
11279 }
11280
11281 static DIALOG csetfix_dlg[] =
11282 {
11283 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11284 { jwin_win_proc, 72, 80, 176+1, 96+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "CSet Fix", NULL, NULL },
11285 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11286 { jwin_radio_proc, 104+22, 108, 80+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "Full Screen", NULL, NULL },
11287 { jwin_radio_proc, 104+22, 118+2, 80+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Dungeon Floor", NULL, NULL },
11288 { d_dummy_proc, 120, 128, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
11289 { jwin_check_proc, 104+22, 128+4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "All Layers", NULL, NULL },
11290 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11291 { jwin_button_proc, 170, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11292 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11293 };
11294
11295 int32_t onCSetFix()
11296 {
11297 restore_mouse();
11298 csetfix_dlg[0].dp2=get_zc_font(font_lfont);
11299 int32_t s=2,x2=14,y2=9;
11300
11301 large_dialog(csetfix_dlg);
11302
11303 if(do_zqdialog(csetfix_dlg,-1)==6)
11304 {
11305 if(csetfix_dlg[2].flags&D_SELECTED)
11306 {
11307 s=0;
11308 x2=16;
11309 y2=11;
11310 }
11311
11312 if(csetfix_dlg[5].flags&D_SELECTED)
11313 {
11314 /*
11315 int32_t drawmap, drawscr;
11316 if (CurrentLayer==0)
11317 {
11318 drawmap=Map.getCurrMap();
11319 drawscr=Map.getCurrScr();
11320 }
11321 else
11322 {
11323 drawmap=Map.CurrScr()->layermap[CurrentLayer-1]-1;
11324 drawscr=Map.CurrScr()->layerscreen[CurrentLayer-1];
11325 }
11326 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
11327 if(!draw_mapscr) return;
11328 saved=false;
11329 Map.Ugo();
11330
11331 if(!(draw_mapscr->valid&mVALID))
11332 {
11333 Map.CurrScr()->valid|=mVALID;
11334 draw_mapscr->valid|=mVALID;
11335 Map.setcolor(Color);
11336 }
11337 for(int32_t i=0; i<176; i++)
11338 {
11339 draw_mapscr->data[i]=Combo;
11340 draw_mapscr->cset[i]=CSet;
11341 }
11342 refresh(rMAP+rSCRMAP);
11343 */
11344 }
11345
11346 Map.StartListCommand();
11347 for(int32_t y=s; y<y2; y++)
11348 {
11349 for(int32_t x=s; x<x2; x++)
11350 {
11351 Map.DoSetComboCommand(Map.getCurrMap(), Map.getCurrScr(), (y<<4)+x, -1, CSet);
11352 }
11353 }
11354 Map.FinishListCommand();
11355
11356 refresh(rMAP);
11357 saved = false;
11358 }
11359
11360 return D_O_K;
11361 }
11362 static bool doAllSolidWater()
11363 {
11364 for(int32_t i=0; i < MAXCOMBOS; ++i)
11365 {
11366 if(combo_class_buf[combobuf[i].type].water!=0)
11367 {
11368 combobuf[i].walk |= 0x0F; //Solid
11369 }
11370 }
11371 return true;
11372 }
11373 static bool doNoSolidWater()
11374 {
11375 for(int32_t i=0; i < MAXCOMBOS; ++i)
11376 {
11377 if(combo_class_buf[combobuf[i].type].water!=0)
11378 {
11379 combobuf[i].walk &= ~0x0F; //Non-solid
11380 }
11381 }
11382 return true;
11383 }
11384 int32_t onWaterSolidity()
11385 {
11386 AlertFuncDialog("Water Conversion",
11387 "Forcibly set the solidity of all 'Liquid' combos in the quest?",
11388 ""
11389 ).add_buttons(2,
11390 { "Solid", "Non-Solid", "Cancel" },
11391 { doAllSolidWater, doNoSolidWater, nullptr }
11392 ).show();
11393 return D_O_K;
11394 }
11395
11396 static bool doAllEffectSquare()
11397 {
11398 for(int32_t i=0; i < MAXCOMBOS; ++i)
11399 {
11400 combobuf[i].walk |= 0xF0; //Effect
11401 }
11402 return true;
11403 }
11404 static bool doBlankEffectSquare()
11405 {
11406 for(int32_t i=0; i < MAXCOMBOS; ++i)
11407 {
11408 if(combobuf[i].is_blank(true))
11409 {
11410 combobuf[i].walk |= 0xF0; //Effect
11411 }
11412 }
11413 return true;
11414 }
11415
11416 int32_t onEffectFix()
11417 {
11418 AlertFuncDialog("Effect Square Conversion",
11419 "Forcibly fill the green effect square of all combos in the quest?",
11420 ""
11421 ).add_buttons(2,
11422 { "All", "Blank Only", "Cancel" },
11423 { doAllEffectSquare, doBlankEffectSquare, nullptr }
11424 ).show();
11425 return D_O_K;
11426 }
11427
11428 static bool clear_green_arrival_squares()
11429 {
11430 for(mapscr& scr : TheMaps)
11431 {
11432 if(!scr.valid) continue;
11433 scr.warparrivalx = 0;
11434 scr.warparrivaly = 0;
11435 }
11436 set_qr(qr_NOARRIVALPOINT, true);
11437 return true;
11438 }
11439
11440 static bool replace_green_arrival_squares()
11441 {
11442 // Check for conflicts first
11443 bool has_conflicts = false;
11444
11445 for(mapscr& scr : TheMaps)
11446 {
11447 if(!scr.valid) continue;
11448 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11449 if(scr.warpreturnx[0] || scr.warpreturny[0])
11450 {
11451 has_conflicts = true;
11452 break;
11453 }
11454 }
11455
11456 enum
11457 {
11458 NOT_ASKED = -1,
11459 MODE_FORCE, MODE_IGNORE, MODE_FIND_IGNORE, MODE_FIND_FORCE, MODE_CANCEL
11460 };
11461 int mode = NOT_ASKED;
11462
11463 if(has_conflicts)
11464 {
11465 AlertFuncDialog("Handle Conflicts",
11466 "Warp Square A is not available for all screens that have arrival squares."
11467 " How should this be handled? (See '?' for more info)",
11468 "Overwrite A: Replace the existing warp return square A with the position of the green arrival square"
11469 "\nIgnore: Do nothing if warp return square A exists"
11470 "\nFind Space or Ignore: Choose another, unused, square to set to the position of the green arrival square."
11471 " If none are unused, 'Ignore' instead."
11472 "\nFind Space or Overwrite: Choose another, unused square to set to the position of the green arrival square."
11473 " If none are unused, 'Overwrite A' instead."
11474 "\nCancel: Don't do anything"
11475 ).add_buttons(1,
11476 { "Overwrite A", "Ignore", "Find Space or Ignore", "Find Space or Overwrite A", "Cancel" },
11477 mode
11478 ).show();
11479 if(mode == NOT_ASKED || mode == MODE_CANCEL)
11480 return false;
11481 }
11482 for(mapscr& scr : TheMaps)
11483 {
11484 if(!scr.valid) continue;
11485 if(!(scr.warparrivalx || scr.warparrivaly)) continue;
11486 int indx = 0;
11487 if(scr.warpreturnx[0] || scr.warpreturny[0])
11488 {
11489 if(mode == MODE_IGNORE) continue; // Warp A not free, so ignore
11490 if(mode != MODE_FORCE)
11491 {
11492 for(int q = 1; q < 4; ++q)
11493 {
11494 if(scr.warpreturnx[q] || scr.warpreturny[q])
11495 continue;
11496 indx = q; // Use this warp, since it's free
11497 break;
11498 }
11499 if(indx == 0 && mode == MODE_FIND_IGNORE)
11500 continue; // Nothing free, so ignore
11501 }
11502 }
11503 scr.warpreturnx[indx] = scr.warparrivalx;
11504 scr.warpreturny[indx] = scr.warparrivaly;
11505 scr.warparrivalx = 0;
11506 scr.warparrivaly = 0;
11507 }
11508 set_qr(qr_NOARRIVALPOINT, true);
11509 return true;
11510 }
11511
11512 int32_t onRemoveOldArrivalSquare()
11513 {
11514 AlertFuncDialog("Arrival Square Removal",
11515 "Clear the old green 'Arrival' squares for the whole quest?"
11516 "\n(There will be no further confirmation, and this operation cannot be undone)",
11517 ""
11518 ).add_buttons(2,
11519 { "Replace With Blue Return Square", "Clear Completely", "Cancel" },
11520 { replace_green_arrival_squares, clear_green_arrival_squares, nullptr }
11521 ).show();
11522 return D_O_K;
11523 }
11524
11525 byte* getPalPointer(int32_t pal, int32_t cset)
11526 {
11527 if (pal < 0) return colordata + CSET(cset)*3;
11528 byte* ret = colordata + CSET(pal*pdLEVEL+poLEVEL)*3;
11529 switch(cset)
11530 {
11531 case 2: case 3: case 4:
11532 return ret + CSET(cset-2)*3;
11533 case 9:
11534 return ret + CSET(3)*3;
11535 case 1:
11536 return ret + CSET(13)*3;
11537 case 5:
11538 return ret + CSET(14)*3;
11539 case 7:
11540 return ret + CSET(15)*3;
11541 case 8:
11542 return ret + CSET(16)*3;
11543 }
11544 return NULL;
11545 }
11546
11547 void copyCSet(int32_t destpal, int32_t destcset, int32_t srcpal, int32_t srccset)
11548 {
11549 byte* dest = getPalPointer(destpal, destcset);
11550 byte* src = getPalPointer(srcpal, srccset);
11551 if (dest && src)
11552 {
11553 memcpy(dest, src, 16*3);
11554 }
11555 }
11556
11557 void setColorPalette(int32_t flags, int32_t lowpal, int32_t highpal)
11558 {
11559 for (auto q = lowpal; q <= highpal; ++q)
11560 {
11561 for (auto c = 0; c < 12; ++c)
11562 {
11563 if (!(flags&(1<<c))) continue;
11564 copyCSet(q, c, -1, c);
11565 }
11566 }
11567 }
11568
11569 void setPitDamage(int32_t flags, int32_t lowcombo, int32_t highcombo, int32_t damage)
11570 {
11571 for(int32_t i=lowcombo; i < highcombo; ++i)
11572 {
11573 if((combobuf[i].type == cPITFALL && (flags & (1<<0)))
11574 || (combobuf[i].type == cWATER && !(combobuf[i].usrflags & (1<<0)) && (flags & (1<<1)))
11575 || (combobuf[i].type == cWATER && (combobuf[i].usrflags & (1<<0)) && (flags & (1<<2))))
11576 {
11577 if ((combobuf[i].type != cPITFALL || (flags & (1<<9)) || !(combobuf[i].usrflags & (1<<0)))
11578 && ((flags & (1<<8)) || combobuf[i].attributes[0] == 0))
11579 combobuf[i].attributes[0] = damage*10000;
11580 }
11581 }
11582 }
11583
11584 static DIALOG template_dlg[] =
11585 {
11586 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
11587 { jwin_win_proc, 72, 80, 176+1, 116+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "NES Dungeon Template", NULL, NULL },
11588 { d_comboframe_proc, 178, 122+3, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
11589 { d_combo_proc, 180, 124+3, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11590 // { d_bitmap_proc, 180, 104, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11591 { jwin_radio_proc, 104+33, 128+3, 64+1, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Floor:", NULL, NULL },
11592 { jwin_radio_proc, 104+33, 148+3, 64+1, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "No Floor", NULL, NULL },
11593 { jwin_button_proc, 90, 172, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11594 { jwin_button_proc, 170, 172, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11595 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11596 { jwin_text_proc, 104, 102, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "This copies the contents of", NULL, NULL },
11597 { jwin_text_proc, 104, 112, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "screen 83 of the current map.", NULL, NULL },
11598 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11599 };
11600
11601 int32_t onTemplate()
11602 {
11603 static bool donethis=false;
11604
11605 if(!donethis||!(key[KEY_LSHIFT]||key[KEY_RSHIFT]))
11606 {
11607 template_dlg[2].d1=Combo;
11608 template_dlg[2].fg=CSet;
11609 donethis=true;
11610 }
11611
11612 restore_mouse();
11613
11614 if(Map.getCurrScr()==TEMPLATE)
11615 return D_O_K;
11616
11617 // BITMAP *floor_bmp = create_bitmap_ex(8,16,16);
11618 // if(!floor_bmp) return D_O_K;
11619 template_dlg[0].dp2=get_zc_font(font_lfont);
11620 // put_combo(floor_bmp,0,0,Combo,CSet,0,0);
11621 // template_dlg[2].dp=floor_bmp;
11622
11623 large_dialog(template_dlg);
11624
11625 if(do_zqdialog(template_dlg,-1)==5)
11626 {
11627 saved=false;
11628 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
11629 Map.DoTemplateCommand((template_dlg[3].flags==D_SELECTED) ? template_dlg[2].d1 : -1, template_dlg[2].fg, screen);
11630 refresh(rMAP+rSCRMAP);
11631 }
11632
11633 // destroy_bitmap(floor_bmp);
11634 return D_O_K;
11635 }
11636
11637 int32_t d_sel_scombo_proc(int32_t msg, DIALOG *d, int32_t c)
11638 {
11639 //these are here to bypass compiler warnings about unused arguments
11640 c=c;
11641
11642 switch(msg)
11643 {
11644 case MSG_CLICK:
11645 while(gui_mouse_b())
11646 {
11647 int32_t x = zc_min(zc_max(gui_mouse_x() - d->x,0)>>4, 15);
11648 int32_t y = zc_min(zc_max(gui_mouse_y() - d->y,0)&0xF0, 160);
11649
11650 if(x+y != d->d1)
11651 {
11652 d->d1 = x+y;
11653 custom_vsync();
11654 d_sel_scombo_proc(MSG_DRAW,d,0);
11655 }
11656 }
11657
11658 break;
11659
11660 case MSG_DRAW:
11661 {
11662 blit((BITMAP*)(d->dp),screen,0,0,d->x,d->y,d->w,d->h);
11663 int32_t x = d->x + (((d->d1)&15)<<4);
11664 int32_t y = d->y + ((d->d1)&0xF0);
11665 rect(screen,x,y,x+15,y+15,vc(15));
11666 }
11667 break;
11668 }
11669
11670 return D_O_K;
11671 }
11672
11673 static DIALOG cflag_dlg[] =
11674 {
11675 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
11676 9 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11677 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
11678 9 { jwin_abclist_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11679 9 { jwin_button_proc, 70, 163, 51, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11680 9 { jwin_button_proc, 190, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11681 9 { jwin_button_proc, 130, 163, 51, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Help", NULL, NULL },
11682 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
11683 };
11684
11685
11686 void questrev_help()
11687 {
11688 jwin_alert("Help","The revision number of your quest.",NULL,NULL,"O&K",NULL,'k',16,get_zc_font(font_lfont));
11689 }
11690
11691 void questminrev_help()
11692 {
11693 jwin_alert("Help","If a player's saved game was from a revision less than the minimum", "revision, they have to restart from the beginning.", "This is useful if you make major changes to your quest.","O&K",NULL,'k',16,get_zc_font(font_lfont));
11694 }
11695
11696 int32_t select_cflag(const char *prompt,int32_t flag)
11697 {
11698 cflag_dlg[0].dp=(void *)prompt;
11699 cflag_dlg[0].dp2=get_zc_font(font_lfont);
11700 GUI::ListData ld = GUI::ZCListData::mapflag(numericalFlags, true);
11701 ListData select_cflag_list = ld.getJWin(&font);
11702 int32_t index = ld.findIndex(flag);
11703 cflag_dlg[2].d1=index;
11704 cflag_dlg[2].dp=(void *) &select_cflag_list;
11705
11706 large_dialog(cflag_dlg);
11707
11708 int32_t ret;
11709
11710 do
11711 {
11712 ret=do_zqdialog(cflag_dlg,2);
11713
11714 if(ret==5)
11715 {
11716 cflag_help(ld.getValue(cflag_dlg[2].d1));
11717 }
11718 }
11719 while(ret==5);
11720
11721 if(ret==0||ret==4)
11722 {
11723 position_mouse_z(0);
11724 return -1;
11725 }
11726
11727 return ld.getValue(cflag_dlg[2].d1);
11728 }
11729
11730 int32_t select_flag(int32_t &f)
11731 {
11732 int32_t ret=select_cflag("Flag Type",f);
11733
11734 if(ret>=0)
11735 {
11736 f=ret;
11737 return true;
11738 }
11739
11740 return false;
11741 }
11742
11743 int32_t d_scombo_proc(int32_t msg,DIALOG *d,int32_t c)
11744 {
11745 //these are here to bypass compiler warnings about unused arguments
11746 c=c;
11747
11748 switch(msg)
11749 {
11750 case MSG_CLICK:
11751 {
11752 int32_t c2=d->d1;
11753 int32_t cs=d->fg;
11754 int32_t f=d->d2;
11755
11756 if(d->bg==1 || (CHECK_CTRL_CMD))
11757 {
11758 while(gui_mouse_b())
11759 {
11760 /* do nothing */
11761 rest(1);
11762 }
11763
11764 if(select_flag(f))
11765 {
11766 d->d2=f;
11767
11768 }
11769 }
11770 else if(key[KEY_LSHIFT])
11771 {
11772 if(gui_mouse_b()&1)
11773 {
11774 d->d1++;
11775
11776 if(d->d1>=MAXCOMBOS) d->d1=0;
11777 }
11778 else if(gui_mouse_b()&2)
11779 {
11780 d->d1--;
11781
11782 if(d->d1<0) d->d1=MAXCOMBOS-1;
11783 }
11784 }
11785 else if(key[KEY_RSHIFT])
11786 {
11787 if(gui_mouse_b()&1)
11788 {
11789 d->fg++;
11790
11791 if(d->fg>11) d->fg=0;
11792 }
11793 else if(gui_mouse_b()&2)
11794 {
11795 d->fg--;
11796
11797 if(d->fg<0) d->fg=11;
11798 }
11799 }
11800 else if(key[KEY_ALT])
11801 {
11802 if(gui_mouse_b()&1)
11803 {
11804 d->d1 = Combo;
11805 d->fg = CSet;
11806 }
11807 }
11808 else
11809 {
11810 if(select_combo_2(c2, cs))
11811 {
11812 d->d1=c2;
11813 d->fg=cs;
11814 }
11815 }
11816
11817 return D_REDRAW;
11818 }
11819 break;
11820
11821 case MSG_DRAW:
11822 d->w = 32;
11823 d->h = 32;
11824
11825 BITMAP *buf = create_bitmap_ex(8,16,16);
11826 BITMAP *bigbmp = create_bitmap_ex(8,d->w,d->h);
11827
11828 if(buf && bigbmp)
11829 {
11830 clear_bitmap(buf);
11831
11832 if(d->bg) //flags only
11833 {
11834 put_flag(buf,0,0,d->d2);
11835 }
11836 else if(d->d1)
11837 {
11838 putcombo(buf,0,0,d->d1,d->fg);
11839
11840 if(Flags&cFLAGS)
11841 put_flags(buf,0,0,d->d1,d->fg,cFLAGS,d->d2);
11842 }
11843
11844 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, d->w, d->h);
11845 destroy_bitmap(buf);
11846 blit(bigbmp,screen,0,0,d->x-1,d->y-1,d->w,d->h);
11847 destroy_bitmap(bigbmp);
11848 }
11849
11850
11851 /*BITMAP *buf = create_bitmap_ex(8,16,16);
11852 if(buf)
11853 {
11854 clear_bitmap(buf);
11855 if(d->d1)
11856 putcombo(buf,0,0,d->d1,d->fg);
11857
11858 blit(buf,screen,0,0,d->x,d->y,d->w,d->h);
11859 destroy_bitmap(buf);
11860 }*/
11861 break;
11862 }
11863
11864 return D_O_K;
11865 }
11866
11867 /*int32_t d_scombo2_proc(int32_t msg, DIALOG *d, int32_t c)
11868 {
11869 //these are here to bypass compiler warnings about unused arguments
11870 c=c;
11871
11872 switch(msg)
11873 {
11874 case MSG_CLICK:
11875 if (CHECK_CTRL_CMD)
11876 {
11877 select_scombo(d->d1);
11878 }
11879 else
11880 {
11881 select_scombo(d->d1);
11882 }
11883 d_scombo_proc(MSG_DRAW,d,0);
11884 break;
11885
11886
11887 case MSG_DRAW:
11888 BITMAP *buf = create_bitmap_ex(8,16,16);
11889 if(buf)
11890 {
11891 clear_bitmap(buf);
11892 Map.draw_secret2(buf,d->d1);
11893 blit(buf,screen,0,0,d->x,d->y,16,16);
11894 destroy_bitmap(buf);
11895 }
11896 break;
11897 }
11898
11899 return D_O_K;
11900 }*/
11901
11902 int32_t onSecretF();
11903
11904 static int32_t secret_burn_list[] =
11905 {
11906 // dialog control number
11907 4, 5, 6, 7, 48, 49, 50, 51, 92, 93, 94, 95, -1
11908 };
11909
11910 static int32_t secret_arrow_list[] =
11911 {
11912 // dialog control number
11913 8, 9, 10, 52, 53, 54, 96, 97, 98, -1
11914 };
11915
11916 static int32_t secret_bomb_list[] =
11917 {
11918 // dialog control number
11919 11, 12, 55, 56, 99, 100, -1
11920 };
11921
11922 static int32_t secret_boomerang_list[] =
11923 {
11924 // dialog control number
11925 13, 14, 15, 57, 58, 59, 101, 102, 103, -1
11926 };
11927
11928 static int32_t secret_magic_list[] =
11929 {
11930 // dialog control number
11931 16, 17, 60, 61, 104, 105, -1
11932 };
11933
11934 static int32_t secret_sword_list[] =
11935 {
11936 // dialog control number
11937 18, 19, 20, 21, 22, 23, 24, 25, 62, 63, 64, 65, 66, 67, 68, 69, 106, 107, 108, 109, 110, 111, 112, 113, -1
11938 };
11939
11940 static int32_t secret_misc_list[] =
11941 {
11942 // dialog control number
11943 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, -1
11944 };
11945
11946 static TABPANEL secret_tabs[] =
11947 {
11948 // (text)
11949 { (char *)"Burn", D_SELECTED, secret_burn_list, 0, NULL },
11950 { (char *)"Arrow", 0, secret_arrow_list, 0, NULL },
11951 { (char *)"Bomb", 0, secret_bomb_list, 0, NULL },
11952 { (char *)"Boomerang", 0, secret_boomerang_list, 0, NULL },
11953 { (char *)"Magic", 0, secret_magic_list, 0, NULL },
11954 { (char *)"Sword", 0, secret_sword_list, 0, NULL },
11955 { (char *)"Misc", 0, secret_misc_list, 0, NULL },
11956 { NULL, 0, NULL, 0, NULL }
11957 };
11958
11959 static DIALOG secret_dlg[] =
11960 {
11961 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3)
11962 { jwin_win_proc, 0, 0, 301, 212, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
11963 { jwin_tab_proc, 6, 25, 289, 156, 0, 0, 0, 0, 0, 0, (void *) secret_tabs, NULL, (void *)secret_dlg },
11964 { jwin_button_proc, 80, 187, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
11965 { jwin_button_proc, 160, 187, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
11966 // 4
11967 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Fire", NULL, NULL },
11968 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Strong Fire", NULL, NULL },
11969 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Fire", NULL, NULL },
11970 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Divine Fire", NULL, NULL },
11971 //8
11972 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Arrow", NULL, NULL },
11973 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Silver Arrow", NULL, NULL },
11974 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Golden Arrow", NULL, NULL },
11975 //11
11976 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Bomb", NULL, NULL },
11977 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Super Bomb", NULL, NULL },
11978 //13
11979 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wooden Boomerang", NULL, NULL },
11980 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Boomerang", NULL, NULL },
11981 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Fire Boomerang", NULL, NULL },
11982 //16
11983 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand Magic", NULL, NULL },
11984 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Magic", NULL, NULL },
11985 //18
11986 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword", NULL, NULL },
11987 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword", NULL, NULL },
11988 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword", NULL, NULL },
11989 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword", NULL, NULL },
11990 { jwin_text_proc, 160, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Sword Beam", NULL, NULL },
11991 { jwin_text_proc, 160, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "White Sword Beam", NULL, NULL },
11992 { jwin_text_proc, 160, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Magic Sword Beam", NULL, NULL },
11993 { jwin_text_proc, 160, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Master Sword Beam", NULL, NULL },
11994 //26
11995 { jwin_text_proc, 12, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Stairs", NULL, NULL },
11996 { jwin_text_proc, 12, 75, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Reflected Fireball", NULL, NULL },
11997 { jwin_text_proc, 12, 97, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hookshot", NULL, NULL },
11998 { jwin_text_proc, 12, 119, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Wand", NULL, NULL },
11999 { jwin_text_proc, 12, 141, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hammer", NULL, NULL },
12000 { jwin_text_proc, 12, 163, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Any Weapon", NULL, NULL },
12001 //32
12002 { jwin_ctext_proc, 235, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Flags 16-31", NULL, NULL },
12003 { jwin_text_proc, 87, 53, 16, 16, vc(11), vc(1), 0, 0, 0, 0, (void *) "Secrets->Next (Flag only)", NULL, NULL },
12004 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 03", NULL, NULL },
12005 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 04", NULL, NULL },
12006 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 05", NULL, NULL },
12007 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 06", NULL, NULL },
12008 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 07", NULL, NULL },
12009 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 08", NULL, NULL },
12010 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 09", NULL, NULL },
12011 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 10", NULL, NULL },
12012 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 11", NULL, NULL },
12013 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 12", NULL, NULL },
12014 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 13", NULL, NULL },
12015 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 14", NULL, NULL },
12016 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 15", NULL, NULL },
12017 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, FR_DEEP, 0, (void *) "Secret Combo 16", NULL, NULL },
12018 //48 (burn)
12019 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12020 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12021 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12022 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12023 //52 (arrow)
12024 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12025 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12026 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12027 //55 (bomb)
12028 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12029 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12030 //57 (boomerang)
12031 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12032 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12033 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12034 //60 (magic)
12035 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12036 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12037 //62 (sword)
12038 { jwin_frame_proc, 108, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12039 { jwin_frame_proc, 108, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12040 { jwin_frame_proc, 108, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12041 { jwin_frame_proc, 108, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12042 { jwin_frame_proc, 256, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12043 { jwin_frame_proc, 256, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12044 { jwin_frame_proc, 256, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12045 { jwin_frame_proc, 256, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12046 //70 (misc)
12047 { jwin_frame_proc, 63, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12048 { jwin_frame_proc, 63, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12049 { jwin_frame_proc, 63, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12050 { jwin_frame_proc, 63, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12051 { jwin_frame_proc, 63, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12052 { jwin_frame_proc, 63, 157, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12053 //76 (16-32)
12054 { jwin_frame_proc, 192, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12055 { jwin_frame_proc, 214, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12056 { jwin_frame_proc, 236, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12057 { jwin_frame_proc, 258, 69, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12058 { jwin_frame_proc, 192, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12059 { jwin_frame_proc, 214, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12060 { jwin_frame_proc, 236, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12061 { jwin_frame_proc, 258, 91, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12062 { jwin_frame_proc, 192, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12063 { jwin_frame_proc, 214, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12064 { jwin_frame_proc, 236, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12065 { jwin_frame_proc, 258, 113, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12066 { jwin_frame_proc, 192, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12067 { jwin_frame_proc, 214, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12068 { jwin_frame_proc, 236, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12069 { jwin_frame_proc, 258, 135, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12070
12071 //92 (burn)
12072 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12073 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12074 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12075 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12076 //96 (arrow)
12077 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12078 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12079 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12080 //99 (bomb)
12081 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12082 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12083 //101 (boomerang)
12084 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12085 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12086 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12087 //104 (magic)
12088 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12089 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12090 //106 (sword)
12091 { d_scombo_proc, 110, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12092 { d_scombo_proc, 110, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12093 { d_scombo_proc, 110, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12094 { d_scombo_proc, 110, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12095 { d_scombo_proc, 258, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12096 { d_scombo_proc, 258, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12097 { d_scombo_proc, 258, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12098 { d_scombo_proc, 258, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12099 //114 (misc)
12100 { d_scombo_proc, 65, 49, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12101 { d_scombo_proc, 65, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12102 { d_scombo_proc, 65, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12103 { d_scombo_proc, 65, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12104 { d_scombo_proc, 65, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12105 { d_scombo_proc, 65, 159, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12106 //120 (16-32)
12107 { d_scombo_proc, 194, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12108 { d_scombo_proc, 216, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12109 { d_scombo_proc, 238, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12110 { d_scombo_proc, 260, 71, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12111 { d_scombo_proc, 194, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12112 { d_scombo_proc, 216, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12113 { d_scombo_proc, 238, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12114 { d_scombo_proc, 260, 93, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12115 { d_scombo_proc, 194, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12116 { d_scombo_proc, 216, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12117 { d_scombo_proc, 238, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12118 { d_scombo_proc, 260, 115, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12119 { d_scombo_proc, 194, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12120 { d_scombo_proc, 216, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12121 { d_scombo_proc, 238, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12122 { d_scombo_proc, 260, 137, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12123 //136 Secrets->Next
12124 { jwin_frame_proc, 158, 47, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12125 { d_scombo_proc, 160, 49, 16, 16, 0, 1, 0, 0, 0, 0, NULL, NULL, NULL },
12126 //138
12127 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12128 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 'f', 0, 0, 0, (void *) onSecretF, NULL, NULL },
12129 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12130 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12131 };
12132
12133 int32_t onSecretF()
12134 {
12135 Flags^=cFLAGS;
12136 object_message(secret_dlg+1, MSG_DRAW, 0);
12137 return D_O_K;
12138 }
12139
12140
12141 int32_t onSecretCombo()
12142 {
12143 secret_dlg[0].dp2=get_zc_font(font_lfont);
12144
12145
12146 mapscr *s;
12147
12148 if(CurrentLayer==0)
12149 {
12150 s=Map.CurrScr();
12151 }
12152 else
12153 {
12154 // s=TheMaps[(Map.CurrScr()->layermap[CurrentLayer-1]-1)*MAPSCRS+(Map.CurrScr()->layerscreen[CurrentLayer-1])];
12155 s=Map.AbsoluteScr((Map.CurrScr()->layermap[CurrentLayer-1]-1), (Map.CurrScr()->layerscreen[CurrentLayer-1]));
12156 }
12157 if(!s) return D_O_K;
12158
12159 char secretcombonumstr[27];
12160 sprintf(secretcombonumstr,"Secret Combos for Layer %d", CurrentLayer);
12161 secret_dlg[0].dp = secretcombonumstr;
12162
12163 secret_dlg[92].d1 = s->secretcombo[sBCANDLE];
12164 secret_dlg[92].fg = s->secretcset[sBCANDLE];
12165 secret_dlg[92].d2 = s->secretflag[sBCANDLE];
12166
12167 secret_dlg[93].d1 = s->secretcombo[sRCANDLE];
12168 secret_dlg[93].fg = s->secretcset[sRCANDLE];
12169 secret_dlg[93].d2 = s->secretflag[sRCANDLE];
12170
12171 secret_dlg[94].d1 = s->secretcombo[sWANDFIRE];
12172 secret_dlg[94].fg = s->secretcset[sWANDFIRE];
12173 secret_dlg[94].d2 = s->secretflag[sWANDFIRE];
12174
12175 secret_dlg[95].d1 = s->secretcombo[sDIVINEFIRE];
12176 secret_dlg[95].fg = s->secretcset[sDIVINEFIRE];
12177 secret_dlg[95].d2 = s->secretflag[sDIVINEFIRE];
12178
12179 secret_dlg[96].d1 = s->secretcombo[sARROW];
12180 secret_dlg[96].fg = s->secretcset[sARROW];
12181 secret_dlg[96].d2 = s->secretflag[sARROW];
12182
12183 secret_dlg[97].d1 = s->secretcombo[sSARROW];
12184 secret_dlg[97].fg = s->secretcset[sSARROW];
12185 secret_dlg[97].d2 = s->secretflag[sSARROW];
12186
12187 secret_dlg[98].d1 = s->secretcombo[sGARROW];
12188 secret_dlg[98].fg = s->secretcset[sGARROW];
12189 secret_dlg[98].d2 = s->secretflag[sGARROW];
12190
12191 secret_dlg[99].d1 = s->secretcombo[sBOMB];
12192 secret_dlg[99].fg = s->secretcset[sBOMB];
12193 secret_dlg[99].d2 = s->secretflag[sBOMB];
12194
12195 secret_dlg[100].d1 = s->secretcombo[sSBOMB];
12196 secret_dlg[100].fg = s->secretcset[sSBOMB];
12197 secret_dlg[100].d2 = s->secretflag[sSBOMB];
12198
12199 for(int32_t i=0; i<3; i++)
12200 {
12201 secret_dlg[101+i].d1 = s->secretcombo[sBRANG+i];
12202 secret_dlg[101+i].fg = s->secretcset[sBRANG+i];
12203 secret_dlg[101+i].d2 = s->secretflag[sBRANG+i];
12204 }
12205
12206 for(int32_t i=0; i<2; i++)
12207 {
12208 secret_dlg[104+i].d1 = s->secretcombo[sWANDMAGIC+i];
12209 secret_dlg[104+i].fg = s->secretcset[sWANDMAGIC+i];
12210 secret_dlg[104+i].d2 = s->secretflag[sWANDMAGIC+i];
12211 }
12212
12213 for(int32_t i=0; i<8; i++)
12214 {
12215 secret_dlg[106+i].d1 = s->secretcombo[sSWORD+i];
12216 secret_dlg[106+i].fg = s->secretcset[sSWORD+i];
12217 secret_dlg[106+i].d2 = s->secretflag[sSWORD+i];
12218 }
12219
12220 secret_dlg[114].d1 = s->secretcombo[sSTAIRS];
12221 secret_dlg[114].fg = s->secretcset[sSTAIRS];
12222 secret_dlg[114].d2 = s->secretflag[sSTAIRS];
12223
12224 secret_dlg[115].d1 = s->secretcombo[sREFFIREBALL];
12225 secret_dlg[115].fg = s->secretcset[sREFFIREBALL];
12226 secret_dlg[115].d2 = s->secretflag[sREFFIREBALL];
12227
12228 for(int32_t i=0; i<4; i++)
12229 {
12230 secret_dlg[116+i].d1 = s->secretcombo[sHOOKSHOT+i];
12231 secret_dlg[116+i].fg = s->secretcset[sHOOKSHOT+i];
12232 secret_dlg[116+i].d2 = s->secretflag[sHOOKSHOT+i];
12233 }
12234
12235 for(int32_t i=0; i<16; i++)
12236 {
12237 secret_dlg[120+i].d1 = s->secretcombo[sSECRET01+i];
12238 secret_dlg[120+i].fg = s->secretcset[sSECRET01+i];
12239 secret_dlg[120+i].d2 = s->secretflag[sSECRET01+i];
12240 }
12241
12242 //Sec->Next doesn't have a combo/cset value associated
12243 secret_dlg[137].d1 = 0;
12244 secret_dlg[137].fg = 0;
12245 secret_dlg[137].d2 = s->secretflag[sSECNEXT];
12246
12247 large_dialog(secret_dlg,1.75);
12248
12249 for(int32_t q = 0; secret_dlg[q].proc != NULL; ++q)
12250 {
12251 if(secret_dlg[q].proc == jwin_frame_proc)
12252 secret_dlg[q].w = secret_dlg[q].h = 36;
12253 }
12254
12255 go();
12256
12257 if(do_zqdialog(secret_dlg,3) == 2)
12258 {
12259 saved = false;
12260 s->secretcombo[sBCANDLE] = secret_dlg[92].d1;
12261 s->secretcset[sBCANDLE] = secret_dlg[92].fg;
12262 s->secretflag[sBCANDLE] = secret_dlg[92].d2;
12263
12264 s->secretcombo[sRCANDLE] = secret_dlg[93].d1;
12265 s->secretcset[sRCANDLE] = secret_dlg[93].fg;
12266 s->secretflag[sRCANDLE] = secret_dlg[93].d2;
12267
12268 s->secretcombo[sWANDFIRE] = secret_dlg[94].d1;
12269 s->secretcset[sWANDFIRE] = secret_dlg[94].fg;
12270 s->secretflag[sWANDFIRE] = secret_dlg[94].d2;
12271
12272 s->secretcombo[sDIVINEFIRE] = secret_dlg[95].d1;
12273 s->secretcset[sDIVINEFIRE] = secret_dlg[95].fg;
12274 s->secretflag[sDIVINEFIRE] = secret_dlg[95].d2;
12275
12276 s->secretcombo[sARROW] = secret_dlg[96].d1;
12277 s->secretcset[sARROW] = secret_dlg[96].fg;
12278 s->secretflag[sARROW] = secret_dlg[96].d2;
12279
12280 s->secretcombo[sSARROW] = secret_dlg[97].d1;
12281 s->secretcset[sSARROW] = secret_dlg[97].fg;
12282 s->secretflag[sSARROW] = secret_dlg[97].d2;
12283
12284 s->secretcombo[sGARROW] = secret_dlg[98].d1;
12285 s->secretcset[sGARROW] = secret_dlg[98].fg;
12286 s->secretflag[sGARROW] = secret_dlg[98].d2;
12287
12288 s->secretcombo[sBOMB] = secret_dlg[99].d1;
12289 s->secretcset[sBOMB] = secret_dlg[99].fg;
12290 s->secretflag[sBOMB] = secret_dlg[99].d2;
12291
12292 s->secretcombo[sSBOMB] = secret_dlg[100].d1;
12293 s->secretcset[sSBOMB] = secret_dlg[100].fg;
12294 s->secretflag[sSBOMB] = secret_dlg[100].d2;
12295
12296 for(int32_t i=0; i<3; i++)
12297 {
12298 s->secretcombo[sBRANG+i] = secret_dlg[101+i].d1;
12299 s->secretcset[sBRANG+i] = secret_dlg[101+i].fg;
12300 s->secretflag[sBRANG+i] = secret_dlg[101+i].d2;
12301 }
12302
12303 for(int32_t i=0; i<2; i++)
12304 {
12305 s->secretcombo[sWANDMAGIC+i] = secret_dlg[104+i].d1;
12306 s->secretcset[sWANDMAGIC+i] = secret_dlg[104+i].fg;
12307 s->secretflag[sWANDMAGIC+i] = secret_dlg[104+i].d2;
12308 }
12309
12310 for(int32_t i=0; i<8; i++)
12311 {
12312 s->secretcombo[sSWORD+i] = secret_dlg[106+i].d1;
12313 s->secretcset[sSWORD+i] = secret_dlg[106+i].fg;
12314 s->secretflag[sSWORD+i] = secret_dlg[106+i].d2;
12315 }
12316
12317 s->secretcombo[sSTAIRS] = secret_dlg[114].d1;
12318 s->secretcset[sSTAIRS] = secret_dlg[114].fg;
12319 s->secretflag[sSTAIRS] = secret_dlg[114].d2;
12320
12321 s->secretcombo[sREFFIREBALL] = secret_dlg[115].d1;
12322 s->secretcset[sREFFIREBALL] = secret_dlg[115].fg;
12323 s->secretflag[sREFFIREBALL] = secret_dlg[115].d2;
12324
12325 for(int32_t i=0; i<4; i++)
12326 {
12327 s->secretcombo[sHOOKSHOT+i] = secret_dlg[116+i].d1;
12328 s->secretcset[sHOOKSHOT+i] = secret_dlg[116+i].fg;
12329 s->secretflag[sHOOKSHOT+i] = secret_dlg[116+i].d2;
12330 }
12331
12332 for(int32_t i=0; i<16; i++)
12333 {
12334 s->secretcombo[sSECRET01+i] = secret_dlg[120+i].d1;
12335 s->secretcset[sSECRET01+i] = secret_dlg[120+i].fg;
12336 s->secretflag[sSECRET01+i] = secret_dlg[120+i].d2;
12337 }
12338 s->secretflag[sSECNEXT] = secret_dlg[137].d2;
12339
12340 }
12341
12342 comeback();
12343 return D_O_K;
12344 }
12345
12346 static DIALOG under_dlg[] =
12347 {
12348 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
12349 { jwin_win_proc, 72, 60, 176+1,120+1,vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12350 { jwin_text_proc, 115, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "Current", NULL, NULL },
12351 { d_comboframe_proc, 122, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12352 { d_combo_proc, 124, 94, 16, 16, 0, 0, 0, D_NOCLICK, 0, 0, NULL, NULL, NULL },
12353 { jwin_text_proc, 184, 83, 20, 20, vc(14), vc(1), 0, 0, 0, 0, (void *) "New", NULL, NULL },
12354 { d_comboframe_proc, 182, 92, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
12355 { d_combo_proc, 184, 94, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12356 { jwin_button_proc, 90, 124, 61, 21, vc(14), vc(1), 's', D_EXIT, 0, 0, (void *) "&Set", NULL, NULL },
12357 { jwin_button_proc, 170, 124, 61, 21, vc(14), vc(1), 'c', D_EXIT, 0, 0, (void *) "&Cancel", NULL, NULL },
12358 { jwin_button_proc, 90, 152, 61, 21, vc(14), vc(1), 'a', D_EXIT, 0, 0, (void *) "Set &All", NULL, NULL },
12359 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
12360 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12361 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12362 };
12363
12364 int32_t onUnderCombo()
12365 {
12366 char titlebuf[64];
12367 sprintf(titlebuf, "Under Combo (Layer %d)", CurrentLayer);
12368 under_dlg[0].dp = titlebuf;
12369 under_dlg[0].dp2 = get_zc_font(font_lfont);
12370 mapscr* scr;
12371 if(CurrentLayer==0)
12372 {
12373 scr=Map.CurrScr();
12374 }
12375 else
12376 {
12377 auto map=Map.CurrScr()->layermap[CurrentLayer-1]-1;
12378 auto screen=Map.CurrScr()->layerscreen[CurrentLayer-1];
12379 scr = Map.AbsoluteScr(map,screen);
12380 }
12381 if(!scr) return D_O_K;
12382
12383 under_dlg[3].d1=scr->undercombo;
12384 under_dlg[3].fg=scr->undercset;
12385
12386 under_dlg[6].d1=Combo;
12387 under_dlg[6].fg=CSet;
12388
12389 large_dialog(under_dlg);
12390 // Doesn't place "New" and "Current" text too well
12391 under_dlg[1].x=342;
12392 under_dlg[4].x=438;
12393
12394 int32_t ret = do_zqdialog(under_dlg,-1);
12395
12396 if(ret==7)
12397 {
12398 saved=false;
12399 scr->undercombo = under_dlg[6].d1;
12400 scr->undercset = under_dlg[6].fg;
12401 }
12402
12403 if(ret==9 && jwin_alert("Confirm Overwrite","Set all Under Combos","on this map?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
12404 {
12405 saved=false;
12406
12407 for(int32_t i=0; i<128; i++)
12408 {
12409 Map.Scr(i)->undercombo = under_dlg[6].d1;
12410 Map.Scr(i)->undercset = under_dlg[6].fg;
12411 }
12412 }
12413
12414 return D_O_K;
12415 }
12416
12417 static DIALOG list_dlg[] =
12418 {
12419 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
12420 9 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12421 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
12422 9 { jwin_list_proc, 72-12-4, 60+4, 176+24+8, 92+3, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
12423 9 { jwin_button_proc, 90, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
12424 9 { jwin_button_proc, 170, 163, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
12425 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
12426 };
12427
12428 /*
12429 typedef struct item_struct {
12430 char *s;
12431 int32_t i;
12432 } item_struct;
12433 */
12434 item_struct bii[MAXITEMS+1];
12435 int32_t bii_cnt=-1;
12436
12437 void build_bii_list(bool usenone)
12438 {
12439 int32_t start=bii_cnt=0;
12440
12441 if(usenone)
12442 {
12443 bii[0].s = (char *)"(None)";
12444 bii[0].i = -2;
12445 bii_cnt=start=1;
12446 }
12447
12448 for(int32_t i=0; i<MAXITEMS; i++)
12449 {
12450 bii[bii_cnt].s = item_string[i];
12451 bii[bii_cnt].i = i;
12452 ++bii_cnt;
12453 }
12454
12455 for(int32_t i=start; i<bii_cnt-1; i++)
12456 {
12457 for(int32_t j=i+1; j<bii_cnt; j++)
12458 {
12459 if(stricmp(bii[i].s,bii[j].s)>0 && strcmp(bii[j].s,""))
12460 {
12461 zc_swap(bii[i],bii[j]);
12462 }
12463 }
12464 }
12465 }
12466
12467
12468 const char *itemlist(int32_t index, int32_t *list_size)
12469 {
12470 if(index<0)
12471 {
12472 *list_size = bii_cnt;
12473 return NULL;
12474 }
12475
12476 return bii[index].s;
12477 }
12478 const char *itemlist_num(int32_t index, int32_t *list_size)
12479 {
12480 if(index<0)
12481 {
12482 *list_size = bii_cnt;
12483 return NULL;
12484 }
12485 static char biin_buf[64+6];
12486 if(bii[index].i < 0)
12487 return bii[index].s;
12488 sprintf(biin_buf, "%s (%03d)", bii[index].s, bii[index].i);
12489 return biin_buf;
12490 }
12491
12492 // disable items on dmaps stuff
12493 int32_t DI[MAXITEMS];
12494 int32_t nDI;
12495
12496 void initDI(int32_t index)
12497 {
12498 int32_t j=0;
12499
12500 for(int32_t i=0; i<MAXITEMS; i++)
12501 {
12502 int32_t index1=bii[i].i; // true index of item in dmap's DI list
12503
12504 if(DMaps[index].disableditems[index1])
12505 {
12506 DI[j]=i;
12507 j++;
12508 }
12509 }
12510
12511 nDI=j;
12512
12513 for(int32_t i=j; i<MAXITEMS; i++) DI[j]=0;
12514
12515 return;
12516 }
12517
12518 void insertDI(int32_t id, int32_t index)
12519 {
12520 int32_t trueid=bii[id].i;
12521 DMaps[index].disableditems[trueid] |= 1; //bit set
12522 initDI(index);
12523 return;
12524 }
12525
12526 void deleteDI(int32_t id, int32_t index)
12527 {
12528 int32_t i=DI[id];
12529 int32_t trueid=bii[i].i;
12530 DMaps[index].disableditems[trueid] &= (~1); // bit clear
12531 initDI(index);
12532 return;
12533 }
12534
12535 const char *DIlist(int32_t index, int32_t *list_size)
12536 {
12537 if(index<0)
12538 {
12539 *list_size = nDI;
12540 return NULL;
12541 }
12542
12543 int32_t i=DI[index];
12544 return bii[i].s;
12545
12546 }
12547
12548 weapon_struct biw[MAXWPNS];
12549 int32_t biw_cnt=-1;
12550
12551 void build_biw_list()
12552 {
12553 int32_t start=biw_cnt=0;
12554
12555 for(int32_t i=start; i<MAXWPNS; i++)
12556 {
12557 biw[biw_cnt].s = (char *)weapon_string[i];
12558 biw[biw_cnt].i = i;
12559 ++biw_cnt;
12560 }
12561
12562 for(int32_t i=start; i<biw_cnt-1; i++)
12563 {
12564 for(int32_t j=i+1; j<biw_cnt; j++)
12565 if(stricmp(biw[i].s,biw[j].s)>0 && strcmp(biw[j].s,""))
12566 zc_swap(biw[i],biw[j]);
12567 }
12568 }
12569
12570 const char *weaponlist(int32_t index, int32_t *list_size)
12571 {
12572 if(index<0)
12573 {
12574 *list_size = biw_cnt;
12575 return NULL;
12576 }
12577
12578 return biw[index].s;
12579 }
12580 const char *weaponlist_num(int32_t index, int32_t *list_size)
12581 {
12582 if(index<0)
12583 {
12584 *list_size = biw_cnt;
12585 return NULL;
12586 }
12587 static char biwn_buf[64+6];
12588 if(biw[index].i < 0)
12589 return biw[index].s;
12590 sprintf(biwn_buf, "%s (%03d)", biw[index].s, biw[index].i);
12591 return biwn_buf;
12592 }
12593 int32_t writeoneweapon(PACKFILE *f, int32_t index)
12594 {
12595 dword section_version=V_WEAPONS;
12596 dword section_cversion=CV_WEAPONS;
12597 int32_t zversion = ZELDA_VERSION;
12598 int32_t zbuild = VERSION_BUILD;
12599 int32_t iid = biw[index].i;
12600 al_trace("Writing Weapon Sprite .zwpnspr file for weapon id: %d\n", iid);
12601
12602 //section version info
12603 if(!p_iputl(zversion,f))
12604 {
12605 return 0;
12606 }
12607 if(!p_iputl(zbuild,f))
12608 {
12609 return 0;
12610 }
12611 if(!p_iputw(section_version,f))
12612 {
12613 return 0;
12614 }
12615
12616 if(!p_iputw(section_cversion,f))
12617 {
12618 return 0;
12619 }
12620
12621 //weapon string
12622
12623 if(!pfwrite((char *)weapon_string[iid], 64, f))
12624 {
12625 return 0;
12626 }
12627
12628 if(!p_putc(wpnsbuf[iid].misc,f))
12629 {
12630 return 0;
12631 }
12632
12633 if(!p_putc(wpnsbuf[iid].csets,f))
12634 {
12635 return 0;
12636 }
12637
12638 if(!p_putc(wpnsbuf[iid].frames,f))
12639 {
12640 return 0;
12641 }
12642
12643 if(!p_putc(wpnsbuf[iid].speed,f))
12644 {
12645 return 0;
12646 }
12647
12648 if(!p_putc(wpnsbuf[iid].type,f))
12649 {
12650 return 0;
12651 }
12652
12653 if(!p_iputw(wpnsbuf[iid].script,f))
12654 {
12655 return 0;
12656 }
12657
12658 //2.55 starts here
12659 if(!p_iputl(wpnsbuf[iid].tile,f))
12660 {
12661 return 0;
12662 }
12663
12664 return 1;
12665 }
12666
12667
12668 int32_t readoneweapon(PACKFILE *f, int32_t index)
12669 {
12670 dword section_version = 0;
12671 dword section_cversion = 0;
12672 int32_t zversion = 0;
12673 int32_t zbuild = 0;
12674 wpndata tempwpnspr;
12675 memset(&tempwpnspr, 0, sizeof(wpndata));
12676
12677
12678 //char dmapstring[64]={0};
12679 //section version info
12680 if(!p_igetl(&zversion,f))
12681 {
12682 return 0;
12683 }
12684 if(!p_igetl(&zbuild,f))
12685 {
12686 return 0;
12687 }
12688 if(!p_igetw(&section_version,f))
12689 {
12690 return 0;
12691 }
12692 if(!p_igetw(&section_cversion,f))
12693 {
12694 return 0;
12695 }
12696 al_trace("readoneweapon section_version: %d\n", section_version);
12697 al_trace("readoneweapon section_cversion: %d\n", section_cversion);
12698
12699 if ( zversion > ZELDA_VERSION )
12700 {
12701 al_trace("Cannot read .zwpnspr packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
12702 return 0;
12703 }
12704
12705 else if ( ( section_version > V_WEAPONS ) || ( section_version == V_WEAPONS && section_cversion < CV_WEAPONS ) )
12706 {
12707 al_trace("Cannot read .zwpnspr packfile made using V_WEAPONS (%d) subversion (%d)\n", section_version, section_cversion);
12708 return 0;
12709
12710 }
12711 else
12712 {
12713 al_trace("Reading a .zwpnspr packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
12714 }
12715
12716 char tmp_wpn_name[64];
12717 memset(tmp_wpn_name,0,64);
12718 if(!pfread(&tmp_wpn_name, 64, f))
12719 {
12720 return 0;
12721 }
12722
12723 word oldtile = 0;
12724 if(section_version < 8)
12725 if(!p_igetw(&oldtile,f))
12726 return 0;
12727
12728 if(!p_getc(&tempwpnspr.misc,f))
12729 {
12730 return 0;
12731 }
12732
12733 if(!p_getc(&tempwpnspr.csets,f))
12734 {
12735 return 0;
12736 }
12737
12738 if(!p_getc(&tempwpnspr.frames,f))
12739 {
12740 return 0;
12741 }
12742
12743 if(!p_getc(&tempwpnspr.speed,f))
12744 {
12745 return 0;
12746 }
12747
12748 if(!p_getc(&tempwpnspr.type,f))
12749 {
12750 return 0;
12751 }
12752
12753 if(!p_igetw(&tempwpnspr.script,f))
12754 {
12755 return 0;
12756 }
12757
12758 //2.55 starts here
12759 if ( zversion >= 0x255 )
12760 {
12761 if ( section_version >= 7 )
12762 {
12763 if(!p_igetl(&tempwpnspr.tile,f))
12764 {
12765 return 0;
12766 }
12767 }
12768 }
12769 if ( zversion < 0x255 )
12770 {
12771 tempwpnspr.tile = oldtile;
12772 }
12773 ::memcpy( &(wpnsbuf[biw[index].i]),&tempwpnspr, sizeof(wpndata));
12774 ::memcpy(weapon_string[biw[index].i], tmp_wpn_name, 64);
12775
12776 return 1;
12777 }
12778
12779 static int32_t seldata_copy;
12780 static void (*seldata_paste_func)(int32_t, int32_t);
12781
12782 void seldata_rclick_func(int32_t index, int32_t x, int32_t y)
12783 {
12784 NewMenu rcmenu {
12785 { "&Copy", [&](){seldata_copy = index;} },
12786 { "Paste", "&v", [&]()
12787 {
12788 seldata_paste_func(seldata_copy, index);
12789 saved = false;
12790 }, 0, seldata_copy < 0 },
12791 };
12792 rcmenu.pop(x, y);
12793 }
12794
12795 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12796 {
12797 if(proc==NULL)
12798 return -1;
12799
12800 list_dlg[0].dp=(void *)prompt;
12801 list_dlg[0].dp2=title_font;
12802 list_dlg[2].d1=index;
12803 ListData select_list(proc, &font);
12804 list_dlg[2].dp=(void *) &select_list;
12805
12806 large_dialog(list_dlg);
12807
12808 seldata_copy=-1;
12809 seldata_paste_func=copyFunc;
12810 if(copyFunc)
12811 {
12812 list_dlg[2].flags|=D_USER<<1;
12813 list_dlg[2].dp3=(void*)seldata_rclick_func;
12814 }
12815 else
12816 {
12817 list_dlg[2].flags&=~(D_USER<<1);
12818 list_dlg[2].dp3=0;
12819 }
12820
12821 int32_t ret=do_zqdialog(list_dlg,2);
12822
12823 if(ret==0||ret==4)
12824 {
12825 position_mouse_z(0);
12826 return -1;
12827 }
12828
12829 return list_dlg[2].d1;
12830 }
12831
12832 int32_t select_data(const char *prompt,int32_t index,const char *(proc)(int32_t,int32_t*), const char *b1, const char *b2, FONT *title_font, void (*copyFunc)(int32_t, int32_t))
12833 {
12834 if(proc==NULL)
12835 return -1;
12836
12837 list_dlg[0].dp=(void *)prompt;
12838 list_dlg[0].dp2=title_font;
12839 list_dlg[2].d1=index;
12840 ListData select_data_list(proc, &font);
12841 list_dlg[2].dp=(void *) &select_data_list;
12842 list_dlg[3].dp=(void *)b1;
12843 list_dlg[4].dp=(void *)b2;
12844
12845 large_dialog(list_dlg);
12846
12847 seldata_copy=-1;
12848 seldata_paste_func=copyFunc;
12849 if(copyFunc)
12850 {
12851 list_dlg[2].flags|=D_USER<<1;
12852 list_dlg[2].dp3=(void*)seldata_rclick_func;
12853 }
12854 else
12855 {
12856 list_dlg[2].flags&=~(D_USER<<1);
12857 list_dlg[2].dp3=0;
12858 }
12859
12860 int32_t ret = do_zqdialog(list_dlg,2);
12861 list_dlg[3].dp=(void *) "OK";
12862 list_dlg[4].dp=(void *) "Cancel";
12863
12864 if(ret==0||ret==4)
12865 {
12866 position_mouse_z(0);
12867 return -1;
12868 }
12869
12870 position_mouse_z(0);
12871 return list_dlg[2].d1;
12872 }
12873
12874 static char sfx_str_buf[42];
12875
12876 const char *sfxlist(int32_t index, int32_t *list_size)
12877 {
12878 if(index>=0)
12879 {
12880 bound(index,0,WAV_COUNT-1);
12881 sprintf(sfx_str_buf,"%d: %s",index, index ? sfx_string[index] : "(None)");
12882 return sfx_str_buf;
12883 }
12884
12885 *list_size=WAV_COUNT;
12886 return NULL;
12887 }
12888
12889 9 static ListData sfx_list(sfxlist, &font);
12890
12891 const char *screenscriptdroplist(int32_t index, int32_t *list_size)
12892 {
12893 if(index<0)
12894 {
12895 *list_size = biscreens_cnt;
12896 return NULL;
12897 }
12898
12899 return biscreens[index].first.c_str();
12900 }
12901
12902 //droplist like the dialog proc, naming scheme for this stuff is awful...
12903 9 static ListData screenscript_list(screenscriptdroplist, &a4fonts[font_pfont]);
12904
12905 int32_t onScreenScript()
12906 {
12907 call_screendata_dialog(7);
12908 return D_O_K;
12909 }
12910
12911 int32_t onScrData()
12912 {
12913 restore_mouse();
12914 call_screendata_dialog();
12915 return D_O_K;
12916 }
12917
12918 const char *roomslist(int32_t index, int32_t *list_size)
12919 {
12920 if(index>=0)
12921 {
12922 if(index>=MAXROOMTYPES)
12923 index=MAXROOMTYPES-1;
12924
12925 return roomtype_string[index];
12926 }
12927
12928 *list_size=MAXROOMTYPES;
12929 return NULL;
12930 }
12931
12932 static char number_str_buf[MIDI_TRACK_BUFFER_SIZE];
12933 int32_t number_list_size=1;
12934 bool number_list_zero=false;
12935
12936 const char *numberlist(int32_t index, int32_t *list_size)
12937 {
12938 if(index>=0)
12939 {
12940 bound(index,0,number_list_size-1);
12941 sprintf(number_str_buf,"%d",index+(number_list_zero?0:1));
12942 return number_str_buf;
12943 }
12944
12945 *list_size=number_list_size;
12946 return NULL;
12947 }
12948
12949 static char dmap_str_buf[37];
12950 int32_t dmap_list_size=MAXDMAPS;
12951 bool dmap_list_zero=true;
12952
12953 const char *dmaplist(int32_t index, int32_t *list_size)
12954 {
12955 if(index>=0)
12956 {
12957 bound(index,0,dmap_list_size-1);
12958 sprintf(dmap_str_buf,"%3d-%s",index+(dmap_list_zero?0:1), DMaps[index].name);
12959 return dmap_str_buf;
12960 }
12961
12962 *list_size=dmap_list_size;
12963 return NULL;
12964 }
12965
12966 char *hexnumlist(int32_t index, int32_t *list_size)
12967 {
12968 if(index>=0)
12969 {
12970 bound(index,0,number_list_size-1);
12971 sprintf(number_str_buf,"%X",index+(number_list_zero?0:1));
12972 return number_str_buf;
12973 }
12974
12975 *list_size=number_list_size;
12976 return NULL;
12977 }
12978
12979 const char *maplist(int32_t index, int32_t *list_size)
12980 {
12981 if(index>=0)
12982 {
12983 bound(index,0,MAXMAPS-1);
12984 sprintf(number_str_buf,"%d",index+1);
12985 return number_str_buf;
12986 }
12987
12988 *list_size=MAXMAPS;
12989 return NULL;
12990 }
12991
12992 const char *gotomaplist(int32_t index, int32_t *list_size)
12993 {
12994 if(index>=0)
12995 {
12996 bound(index,0,map_count-1);
12997 sprintf(number_str_buf,"%d",index+1);
12998 return number_str_buf;
12999 }
13000
13001 *list_size = map_count;
13002 return NULL;
13003 }
13004
13005 const char *midilist(int32_t index, int32_t *list_size)
13006 {
13007 if(index>=0)
13008
13009 {
13010 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13011 return midi_string[index];
13012 }
13013
13014 *list_size=MAXCUSTOMMIDIS_ZQ;
13015 return NULL;
13016 }
13017
13018 const char *custommidilist(int32_t index, int32_t *list_size)
13019 {
13020 if(index>=0)
13021 {
13022 bound(index,0,MAXCUSTOMMIDIS_ZQ-1);
13023 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),customtunes[index].data?customtunes[index].title:"(Empty)");
13024 return number_str_buf;
13025 }
13026
13027 *list_size=number_list_size;
13028 return NULL;
13029 }
13030
13031 const char *enhancedmusiclist(int32_t index, int32_t *list_size)
13032 {
13033 index=index; //this is here to prevent unused parameter warnings
13034 list_size=list_size; //this is here to prevent unused parameter warnings
13035 /*if(index>=0)
13036 {
13037 bound(index,0,MAXMUSIC-1);
13038 sprintf(number_str_buf,"%3d - %s",index+(number_list_zero?0:1),enhancedMusic[index].filename[0]?enhancedMusic[index].title:"(Empty)" );
13039 return number_str_buf;
13040 }
13041 *list_size=number_list_size;*/
13042 return NULL;
13043 }
13044
13045
13046 const char *levelnumlist(int32_t index, int32_t *list_size)
13047 {
13048 if(index>=0)
13049 {
13050 bound(index,0,0xFFF);
13051 sprintf(number_str_buf,"%.3X - %s",index,palnames[index]);
13052 return number_str_buf;
13053 }
13054
13055 *list_size=MAXLEVELS;
13056 return NULL;
13057 }
13058
13059 static char shop_str_buf[40];
13060 int32_t shop_list_size=1;
13061
13062 const char *shoplist(int32_t index, int32_t *list_size)
13063 {
13064 if(index>=0)
13065 {
13066 bound(index,0,shop_list_size-1);
13067 sprintf(shop_str_buf,"%3d: %s",index,QMisc.shop[index].name);
13068 return shop_str_buf;
13069 }
13070
13071 *list_size=shop_list_size;
13072 return NULL;
13073 }
13074
13075 static char bottle_str_buf[40];
13076 int32_t bottle_list_size=1;
13077
13078 const char *bottlelist(int32_t index, int32_t *list_size)
13079 {
13080 if(index>=0)
13081 {
13082 bound(index,0,bottle_list_size-1);
13083 sprintf(bottle_str_buf,"%2d: %s",index+1,QMisc.bottle_types[index].name);
13084 return bottle_str_buf;
13085 }
13086
13087 *list_size=bottle_list_size;
13088 return NULL;
13089 }
13090
13091 static char bottleshop_str_buf[40];
13092 int32_t bottleshop_list_size=1;
13093
13094 const char *bottleshoplist(int32_t index, int32_t *list_size)
13095 {
13096 if(index>=0)
13097 {
13098 bound(index,0,bottleshop_list_size-1);
13099 sprintf(bottleshop_str_buf,"%3d: %s",index,QMisc.bottle_shop_types[index].name);
13100 return bottleshop_str_buf;
13101 }
13102
13103 *list_size=bottleshop_list_size;
13104 return NULL;
13105 }
13106
13107 static char info_str_buf[40];
13108 int32_t info_list_size=1;
13109
13110 const char *infolist(int32_t index, int32_t *list_size)
13111 {
13112 if(index>=0)
13113 {
13114 bound(index,0,info_list_size-1);
13115 sprintf(info_str_buf,"%3d: %s",index,QMisc.info[index].name);
13116 return info_str_buf;
13117 }
13118
13119 *list_size=info_list_size;
13120 return NULL;
13121 }
13122
13123 bool mapcount_will_affect_layers(word newmapcount)
13124 {
13125 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13126 {
13127 mapscr *layerchecker=&TheMaps[i];
13128
13129 for(int32_t j=0; j<6; j++)
13130 {
13131 if(layerchecker->layermap[j]>(newmapcount))
13132 {
13133 return true;
13134 }
13135 }
13136 }
13137 return false;
13138 }
13139
13140 void update_map_count(word newmapcount)
13141 {
13142 if(map_count == newmapcount) return;
13143 saved = false;
13144 setMapCount2(newmapcount);
13145 //Prevent the nine 'last mapscreen' buttons from pointing to invlid locations
13146 //if the user reduces the mapcount. -Z ( 23rd September, 2019 )
13147 for ( int32_t q = 0; q < 9; q++ )
13148 {
13149 map_page[q].map = ( map_page[q].map > newmapcount-1 ) ? newmapcount-1 : map_page[q].map;
13150 }
13151 for(int32_t i=0; i<(newmapcount)*MAPSCRS; i++)
13152 {
13153 fix_layers(&TheMaps[i], false);
13154 }
13155
13156 refresh(rMAP+rSCRMAP+rMENU);
13157 }
13158
13159 int32_t onGotoMap()
13160 {
13161 int32_t ret = select_data("Goto Map",Map.getCurrMap(),gotomaplist,get_zc_font(font_lfont));
13162
13163 if(ret >= 0)
13164 {
13165 int32_t m=Map.getCurrMap();
13166 Map.setCurrMap(ret);
13167 }
13168
13169 refresh(rALL);
13170 return D_O_K;
13171 }
13172
13173 int32_t onFlags()
13174 {
13175 restore_mouse();
13176 int32_t ret=select_cflag("Select Combo Flag",Flag);
13177 position_mouse_z(0);
13178
13179 if(ret>=0)
13180 {
13181 Flag=ret;
13182 refresh(rMENU);
13183 doflags();
13184 }
13185
13186 return D_O_K;
13187 }
13188
13189 static DIALOG usedcombo_list_dlg[] =
13190 {
13191 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13192 9 { jwin_win_proc, 60-12, 40, 200+24, 148, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combos Used", NULL, NULL },
13193 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13194 9 { jwin_textbox_proc, 72-12, 60+4, 176+24+1, 92+4, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, NULL, NULL, NULL },
13195 9 { jwin_button_proc, 130, 163, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13196 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13197 };
13198
13199
13200
13201 int32_t onUsedCombos()
13202 {
13203 restore_mouse();
13204 usedcombo_list_dlg[0].dp2=get_zc_font(font_lfont);
13205
13206 int32_t usedcombos[7][300][2];
13207 char combolist_text[65536];
13208 char temptext[80];
13209
13210 int32_t drawmap=Map.getCurrMap();
13211 int32_t drawscr=Map.getCurrScr();
13212 int32_t counter[7];
13213
13214 for(int32_t layer=0; layer<7; ++layer)
13215 {
13216 counter[layer]=0;
13217
13218 if(layer==0)
13219 {
13220 drawmap=Map.getCurrMap();
13221 drawscr=Map.getCurrScr();
13222 }
13223 else
13224 {
13225 drawmap=Map.CurrScr()->layermap[layer-1]-1;
13226 drawscr=Map.CurrScr()->layerscreen[layer-1];
13227 }
13228 mapscr* draw_mapscr = Map.AbsoluteScr(drawmap, drawscr);
13229 if(!draw_mapscr) continue;
13230
13231 usedcombos[layer][0][0]=draw_mapscr->data[0];
13232 usedcombos[layer][0][1]=1;
13233 counter[layer]=1;
13234
13235 for(int32_t i=1; i<176; ++i)
13236 {
13237 bool used=false;
13238
13239 for(int32_t j=0; j<counter[layer]; ++j)
13240 {
13241 if(usedcombos[layer][j][0]==draw_mapscr->data[i])
13242 {
13243 ++usedcombos[layer][j][1];
13244 used=true;
13245 break;
13246 }
13247 }
13248
13249 if(!used)
13250 {
13251 usedcombos[layer][counter[layer]][0]=draw_mapscr->data[i];
13252 usedcombos[layer][counter[layer]][1]=1;
13253 ++counter[layer];
13254 }
13255 }
13256
13257 for(int32_t i=0; i<counter[layer]-1; i++)
13258 {
13259 for(int32_t j=i+1; j<counter[layer]; j++)
13260 {
13261 if(usedcombos[layer][i][0]>usedcombos[layer][j][0])
13262 {
13263 zc_swap(usedcombos[layer][i][0],usedcombos[layer][j][0]);
13264 zc_swap(usedcombos[layer][i][1],usedcombos[layer][j][1]);
13265 }
13266 }
13267 }
13268 }
13269
13270 sprintf(combolist_text, " ");
13271
13272 for(int32_t layer=0; layer<7; ++layer)
13273 {
13274 if(counter[layer]>0)
13275 {
13276 if(layer>0)
13277 {
13278 strcat(combolist_text, "\n");
13279 }
13280
13281 sprintf(temptext, "Combos on layer %d\n-----------------\n", layer);
13282 strcat(combolist_text, temptext);
13283
13284 for(int32_t i=0; i<counter[layer]; i++)
13285 {
13286 if((i<counter[layer]-1) && (((usedcombos[layer][i][1]==usedcombos[layer][i+1][1]&&(usedcombos[layer][i][0]+1==usedcombos[layer][i+1][0])) && ((i==0) || ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))))
13287 {
13288 sprintf(temptext, "%5d ", usedcombos[layer][i][0]);
13289 strcat(combolist_text, temptext);
13290 }
13291 else if(((i>0) && (((usedcombos[layer][i][1]==usedcombos[layer][i-1][1])&&((usedcombos[layer][i][0]-1==usedcombos[layer][i-1][0]))) && ((i==counter[layer]-1) || ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0])))))))
13292 {
13293 sprintf(temptext, "- %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13294 strcat(combolist_text, temptext);
13295 }
13296 else if(((i==0) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))))||
13297 ((i==counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0]))))||
13298 ((i>0) && (i<counter[layer]-1) && ((usedcombos[layer][i][1]!=usedcombos[layer][i+1][1])||((usedcombos[layer][i][0]+1!=usedcombos[layer][i+1][0]))) && ((usedcombos[layer][i][1]!=usedcombos[layer][i-1][1])||((usedcombos[layer][i][0]-1!=usedcombos[layer][i-1][0])))))
13299 {
13300 sprintf(temptext, " %5d (%3d)\n", usedcombos[layer][i][0],usedcombos[layer][i][1]);
13301 strcat(combolist_text, temptext);
13302 }
13303 }
13304 }
13305 }
13306
13307 strcat(combolist_text, "\n");
13308 usedcombo_list_dlg[2].dp=combolist_text;
13309 usedcombo_list_dlg[2].d2=0;
13310
13311 large_dialog(usedcombo_list_dlg);
13312
13313 do_zqdialog(usedcombo_list_dlg,2);
13314 position_mouse_z(0);
13315 return D_O_K;
13316 }
13317
13318 int32_t onItem()
13319 {
13320 restore_mouse();
13321 int32_t exit_status;
13322 int32_t current_item=Map.CurrScr()->hasitem != 0 ? Map.CurrScr()->item : -1;
13323
13324 ItemListerDialog(current_item,true).show();
13325 if(current_item != lister_sel_val)
13326 {
13327 if(lister_sel_val>=0)
13328 {
13329 saved = false;
13330 Map.CurrScr()->item = lister_sel_val;
13331 Map.CurrScr()->hasitem = true;
13332 }
13333 else
13334 {
13335 saved = false;
13336 Map.CurrScr()->hasitem = false;
13337 }
13338 }
13339
13340 refresh(rMAP+rMENU);
13341 return D_O_K;
13342 }
13343
13344 void call_room_dlg(mapscr* scr);
13345 int32_t onRoom()
13346 {
13347 restore_mouse();
13348 auto* scr = Map.CurrScr();
13349 call_room_dlg(scr);
13350
13351 refresh(rMAP+rMENU);
13352 return D_O_K;
13353 }
13354
13355 int32_t onEndString()
13356 {
13357 int32_t ret=select_data("Select Ending String",QMisc.endstring,msgslist,get_zc_font(font_lfont));
13358
13359 if(ret>=0)
13360 {
13361 saved=false;
13362 QMisc.endstring=msglistcache[ret];
13363 }
13364
13365 refresh(rMENU);
13366 return D_O_K;
13367 }
13368
13369 9 static ListData levelnum_list(levelnumlist, &font);
13370
13371 static DIALOG screen_pal_dlg[] =
13372 {
13373 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
13374 9 { jwin_win_proc, 60-12, 40, 200-16, 96, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Palette", NULL, NULL },
13375 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13376 9 { jwin_droplist_proc, 72-12, 84+4, 161, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &levelnum_list, NULL, NULL },
13377 9 { jwin_button_proc, 70, 111, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13378 9 { jwin_button_proc, 150, 111, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13379 9 { jwin_text_proc, 72-12, 60+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Note: This does not affect how the", NULL, NULL },
13380 9 { jwin_text_proc, 72-12, 72+4, 168, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "room will be displayed in-game!", NULL, NULL },
13381 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13382 };
13383 // return list_dlg[2].d1;
13384
13385 int32_t onScreenPalette()
13386 {
13387 restore_mouse();
13388 screen_pal_dlg[0].dp2=get_zc_font(font_lfont);
13389 auto oldcol = screen_pal_dlg[2].d1 = Map.getcolor();
13390
13391 large_dialog(screen_pal_dlg);
13392 auto old_valid = Map.CurrScr()->valid;
13393 pause_dlg_tint(true);
13394 zq_set_screen_never_freeze(true);
13395 while(true)
13396 {
13397 auto ret = do_zqdialog(screen_pal_dlg,2);
13398 if(ret == 2)
13399 {
13400 Map.setcolor(screen_pal_dlg[2].d1);
13401 refresh(rALL);
13402 }
13403 else
13404 {
13405 if(ret == 3)
13406 {
13407 if(screen_pal_dlg[2].d1 != oldcol)
13408 saved=false;
13409 Map.setcolor(screen_pal_dlg[2].d1);
13410 }
13411 else
13412 {
13413 Map.setcolor(oldcol);
13414 Map.CurrScr()->valid = old_valid;
13415 }
13416 refresh(rALL);
13417 break;
13418 }
13419 }
13420 pause_dlg_tint(false);
13421 zq_set_screen_never_freeze(false);
13422
13423 rebuild_trans_table();
13424
13425 return D_O_K;
13426 }
13427
13428 int32_t onDecScrPal()
13429 {
13430 if(DisableLPalShortcuts)
13431 {
13432 lpal_dsa();
13433 return D_O_K;
13434 }
13435 restore_mouse();
13436 int32_t c=Map.getcolor();
13437 c+=511;
13438 c=c%512;
13439 Map.setcolor(c);
13440 refresh(rALL);
13441 saved = false;
13442 return D_O_K;
13443 }
13444
13445 int32_t onIncScrPal()
13446 {
13447 if(DisableLPalShortcuts)
13448 {
13449 lpal_dsa();
13450 return D_O_K;
13451 }
13452 restore_mouse();
13453 int32_t c=Map.getcolor();
13454 c+=1;
13455 c=c%512;
13456 Map.setcolor(c);
13457 refresh(rALL);
13458 saved = false;
13459 return D_O_K;
13460 }
13461
13462 int32_t PalWrap(int32_t kX, int32_t const kLowerBound, int32_t const kUpperBound)
13463 {
13464 int32_t range_size = kUpperBound - kLowerBound + 1;
13465
13466 if (kX < kLowerBound)
13467 kX += range_size * ((kLowerBound - kX) / range_size + 1);
13468
13469 return kLowerBound + (kX - kLowerBound) % range_size;
13470 }
13471
13472 int32_t onDecScrPal16()
13473 {
13474 if(DisableLPalShortcuts)
13475 {
13476 lpal_dsa();
13477 return D_O_K;
13478 }
13479 restore_mouse();
13480 int32_t c=Map.getcolor();
13481
13482 c = PalWrap( ( c-0x10 ), 0, 511 );
13483
13484 Map.setcolor(c);
13485 refresh(rALL);
13486 saved = false;
13487 return D_O_K;
13488 }
13489
13490 int32_t onIncScrPal16()
13491 {
13492 if(DisableLPalShortcuts)
13493 {
13494 lpal_dsa();
13495 return D_O_K;
13496 }
13497 restore_mouse();
13498 int32_t c=Map.getcolor();
13499
13500 c = PalWrap( ( c+0x10 ), 0, 511 );
13501 Map.setcolor(c);
13502 refresh(rALL);
13503 saved = false;
13504 return D_O_K;
13505 }
13506
13507 int32_t onZoomIn()
13508 {
13509 change_mapscr_zoom(-1);
13510 return D_O_K;
13511 }
13512
13513 int32_t onZoomOut()
13514 {
13515 change_mapscr_zoom(1);
13516 return D_O_K;
13517 }
13518
13519 int32_t d_ndroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13520 {
13521 int32_t ret = jwin_droplist_proc(msg,d,c);
13522
13523 // The only place this proc is used is in the info type editor.
13524 // If it's ever used anywhere else, this will probably need to be changed.
13525 // Maybe add a flag for it or something.
13526 int32_t msgID=msg_at_pos(d->d1);
13527
13528 switch(msg)
13529 {
13530 case MSG_DRAW:
13531 case MSG_CHAR:
13532 case MSG_CLICK:
13533 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",msgID);
13534 }
13535
13536 return ret;
13537 }
13538
13539 int32_t d_idroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13540 {
13541 int32_t ret = jwin_droplist_proc(msg,d,c);
13542
13543 switch(msg)
13544 {
13545 case MSG_DRAW:
13546 case MSG_CHAR:
13547 case MSG_CLICK:
13548 int32_t tile = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].tile : 0;
13549 int32_t cset = bii[d->d1].i >=0 ? itemsbuf[bii[d->d1].i].csets&15 : 0;
13550 int32_t x = d->x + d->w + 4;
13551 int32_t y = d->y - 8;
13552 int32_t w = 32;
13553 int32_t h = 32;
13554
13555 BITMAP *buf = create_bitmap_ex(8,16,16);
13556 BITMAP *bigbmp = create_bitmap_ex(8,w,h);
13557
13558 if(buf && bigbmp)
13559 {
13560 clear_bitmap(buf);
13561
13562 if(tile)
13563 overtile16(buf, tile,0,0,cset,0);
13564
13565 stretch_blit(buf, bigbmp, 0,0, 16, 16, 0, 0, w, h);
13566 destroy_bitmap(buf);
13567 jwin_draw_frame(screen,x,y,w+4,h+4,FR_DEEP);
13568 blit(bigbmp,screen,0,0,x+2,y+2,w,h);
13569 destroy_bitmap(bigbmp);
13570 }
13571
13572 }
13573
13574 return ret;
13575 }
13576
13577 int32_t d_nidroplist_proc(int32_t msg,DIALOG *d,int32_t c)
13578 {
13579 int32_t ret = d_idroplist_proc(msg,d,c);
13580
13581 switch(msg)
13582 {
13583 case MSG_DRAW:
13584 case MSG_CHAR:
13585 case MSG_CLICK:
13586 textprintf_ex(screen,font,d->x - 48,d->y + 4,jwin_pal[jcBOXFG],jwin_pal[jcBOX],"%5d",bii[d->d1].i);
13587 }
13588
13589 return ret;
13590 }
13591
13592 // Triforce pieces
13593 static byte triframe_points[9*4] =
13594 {
13595 0,2,2,0, 2,0,4,2, 0,2,4,2, 1,1,3,1, 2,0,2,2,
13596 1,1,1,2, 1,1,2,2, 3,1,3,2, 3,1,2,2
13597 };
13598
13599 int32_t d_tri_frame_proc(int32_t msg,DIALOG *d,int32_t c)
13600 {
13601 //these are here to bypass compiler warnings about unused arguments
13602 c=c;
13603
13604 if(msg==MSG_DRAW)
13605 {
13606 int32_t x[5],y[3];
13607
13608 x[0]=d->x;
13609 x[1]=d->x+(d->w>>2);
13610 x[2]=d->x+(d->w>>1);
13611 x[3]=d->x+(d->w>>1)+(d->w>>2);
13612 x[4]=d->x+d->w;
13613 y[0]=d->y;
13614 y[1]=d->y+(d->h>>1);
13615 y[2]=d->y+d->h;
13616
13617 byte *p = triframe_points;
13618
13619 for(int32_t i=0; i<9; i++)
13620 {
13621 line(screen,x[*p],y[*(p+1)],x[*(p+2)],y[*(p+3)],d->fg);
13622 p+=4;
13623 }
13624 }
13625
13626 return D_O_K;
13627 }
13628
13629 int32_t d_tri_edit_proc(int32_t msg,DIALOG *d,int32_t c)
13630 {
13631 jwin_button_proc(msg,d,c);
13632
13633 if(msg==MSG_CLICK)
13634 {
13635 int32_t v = getnumber("Piece Number",d->d1);
13636
13637 if(v>=0)
13638 {
13639 bound(v,1,8);
13640
13641 if(v!=d->d1)
13642 {
13643 DIALOG *tp = d - d->d2;
13644
13645 for(int32_t i=0; i<8; i++)
13646 {
13647 if(tp->d1==v)
13648 {
13649 tp->d1 = d->d1;
13650 ((char*)(tp->dp))[0] = d->d1+'0';
13651 jwin_button_proc(MSG_DRAW,tp,0);
13652 }
13653
13654 ++tp;
13655 }
13656
13657 d->d1 = v;
13658 ((char*)(d->dp))[0] = v+'0';
13659 }
13660 }
13661
13662 d->flags = 0;
13663 jwin_button_proc(MSG_DRAW,d,0);
13664 }
13665
13666 return D_O_K;
13667 }
13668
13669 static DIALOG tp_dlg[] =
13670 {
13671 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13672 9 { jwin_win_proc, 56, 32, 208, 160, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Triforce Pieces", NULL, NULL },
13673 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13674 9 { d_tri_frame_proc, 64, 56, 192, 96, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, NULL, NULL, NULL },
13675 // 3
13676 9 { d_tri_edit_proc, 138, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
13677 9 { d_tri_edit_proc, 166, 82, 17, 17, vc(14), vc(1), 0, 0, 0, 1, (void *) "2", NULL, NULL },
13678 9 { d_tri_edit_proc, 90, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 2, (void *) "3", NULL, NULL },
13679 9 { d_tri_edit_proc, 214, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 3, (void *) "4", NULL, NULL },
13680 // 7
13681 9 { d_tri_edit_proc, 138, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 4, (void *) "5", NULL, NULL },
13682 9 { d_tri_edit_proc, 118, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 5, (void *) "6", NULL, NULL },
13683 9 { d_tri_edit_proc, 166, 110, 17, 17, vc(14), vc(1), 0, 0, 0, 6, (void *) "7", NULL, NULL },
13684 9 { d_tri_edit_proc, 186, 130, 17, 17, vc(14), vc(1), 0, 0, 0, 7, (void *) "8", NULL, NULL },
13685 // 11
13686 9 { jwin_button_proc, 90, 166, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13687 9 { jwin_button_proc, 170, 166, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13688 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13689 };
13690
13691 int32_t onTriPieces()
13692 {
13693 tp_dlg[0].dp2=get_zc_font(font_lfont);
13694 char temptext[8][2];
13695
13696 for(int32_t i=0; i<8; i++)
13697 {
13698 tp_dlg[i+3].d1 = QMisc.triforce[i];
13699 // ((char*)(tp_dlg[i+3].dp))[0] = QMisc.triforce[i]+'0';
13700 sprintf(temptext[i], "%d", QMisc.triforce[i]);
13701 tp_dlg[i+3].dp=temptext[i];
13702 }
13703
13704 large_dialog(tp_dlg);
13705
13706 if(do_zqdialog(tp_dlg,-1) == 11)
13707 {
13708 saved=false;
13709
13710 for(int32_t i=0; i<8; i++)
13711 QMisc.triforce[i] = tp_dlg[i+3].d1;
13712 }
13713
13714 return D_O_K;
13715 }
13716
13717 int32_t d_maptile_proc(int32_t msg,DIALOG *d,int32_t c);
13718 bool small_dmap=false;
13719
13720 static DIALOG dmapmaps_dlg[] =
13721 {
13722
13723 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
13724 { jwin_win_proc, 4, 18, 313, 217, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Custom DMap Map Styles", NULL, NULL },
13725 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13726 { jwin_button_proc, 93, 208, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
13727 { jwin_button_proc, 168, 208, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
13728 { d_ctext2_proc, 160, 38, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimaps", NULL, NULL },
13729 { d_ctext2_proc, 112, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13730 { d_ctext2_proc, 208, 46, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13731
13732 { d_ctext2_proc, 162, 110, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Large Maps", NULL, NULL },
13733 { d_ctext2_proc, 80, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Without Map", NULL, NULL },
13734 { d_ctext2_proc, 240, 118, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "With Map", NULL, NULL },
13735 // 5
13736 { d_maptile_proc, 72, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13737 { d_maptile_proc, 168, 54, 80, 48, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13738 { d_maptile_proc, 8, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13739 { d_maptile_proc, 168, 126, 144, 80, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
13740 // 11
13741 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
13742 };
13743
13744 int32_t d_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
13745 {
13746 return jwin_hexedit_proc(msg,d,c);
13747 }
13748
13749 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13750 {
13751 if(div!=-1)
13752 rectfill(dest,x-1,y-1,x+63,y+3,div);
13753
13754 for(int32_t dx=0; dx<64; dx+=8)
13755 {
13756 if(grid&0x80)
13757 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13758 else if(bg!=-1)
13759 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13760
13761 grid<<=1;
13762 }
13763 }
13764
13765 void drawovergrid(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t color,int32_t div)
13766 {
13767 if(div!=-1)
13768 rectfill(dest,x-1,y-1,x+63,y+3,div);
13769
13770 for(int32_t dx=0; dx<64; dx+=4)
13771 {
13772 rectfill(dest,x+dx,y,x+dx+2,y+2,color);
13773 grid<<=1;
13774 }
13775 }
13776
13777 void drawgrid(BITMAP *dest,int32_t x,int32_t y,int32_t w, int32_t h, int32_t tw, int32_t th, int32_t *grid,int32_t fg,int32_t bg,int32_t div)
13778 {
13779 //these are here to bypass compiler warnings about unused arguments
13780 w=w;
13781 tw=tw;
13782 th=th;
13783
13784 rectfill(dest,x,y,x+(8*8),y+(1*4),div);
13785
13786 for(int32_t dy=0; dy<h; dy++)
13787 {
13788 for(int32_t dx=0; dx<64; dx+=8)
13789 {
13790 if(grid[0]&0x80)
13791 rectfill(dest,x+dx,y,x+dx+6,y+2,fg);
13792 else
13793 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13794
13795 grid[0]<<=1;
13796 }
13797 }
13798 }
13799
13800 void drawgrid_s(BITMAP *dest,int32_t x,int32_t y,int32_t grid,int32_t fg,int32_t bg,int32_t div)
13801 {
13802 rectfill(dest,x-1,y-1,x+63,y+3,div);
13803
13804 for(int32_t dx=0; dx<64; dx+=8)
13805 {
13806 rectfill(dest,x+dx,y,x+dx+6,y+2,bg);
13807
13808 if(grid&0x80)
13809 rectfill(dest,x+dx+2,y,x+dx+4,y+2,fg);
13810
13811 grid<<=1;
13812 }
13813 }
13814
13815 void drawdmap(int32_t dmap)
13816 {
13817 int32_t c;
13818 zcolors mc=QMisc.colors;
13819
13820 switch((DMaps[dmap].type&dmfTYPE))
13821 {
13822 case dmDNGN:
13823 case dmCAVE:
13824 clear_bitmap(dmapbmp_small);
13825
13826 if(DMaps[dmap].minimap_2_tile)
13827 ;
13828 // overworld_map_tile overrides the NES minimap. dungeon_map_tile does not.
13829 else for(int32_t y=1; y<33; y+=4)
13830 drawgrid(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2], DMaps[dmap].flags&dmfMINIMAPCOLORFIX ? mc.cave_fg : mc.dngn_fg, -1, -1);
13831
13832 c=DMaps[dmap].compass;
13833 // rectfill(dmapbmp,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,dvc(2*4));
13834 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(4));
13835 c=DMaps[dmap].cont;
13836 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13837 break;
13838
13839 case dmOVERW:
13840 clear_bitmap(dmapbmp_small);
13841
13842 if(DMaps[dmap].minimap_2_tile)
13843 ;
13844 else if(!mc.overworld_map_tile)
13845 for(int32_t y=1; y<33; y+=4)
13846 drawovergrid(dmapbmp_small,1,y,DMaps[dmap].grid[y>>2],mc.overw_bg,vc(0));
13847
13848 c=DMaps[dmap].cont;
13849 rectfill(dmapbmp_small,(c&15)*4+1,(c>>4)*4+1,(c&15)*4+3,(c>>4)*4+3,vc(10));
13850 break;
13851
13852 case dmBSOVERW:
13853 clear_bitmap(dmapbmp_small);
13854
13855 if(DMaps[dmap].minimap_2_tile)
13856 ;
13857 else if(!mc.overworld_map_tile)
13858 for(int32_t y=1; y<33; y+=4)
13859 // drawgrid_s(dmapbmp,1,y,DMaps[dmap].grid[y>>2],dvc(2*4),dvc(2*3),dvc(3+4));
13860 drawgrid_s(dmapbmp_small,0,y,DMaps[dmap].grid[y>>2],mc.bs_goal,mc.bs_dk,vc(14));
13861
13862 c=DMaps[dmap].cont;
13863 rectfill(dmapbmp_small,(c&15)*8+3,(c>>4)*4+1,(c&15)*8+5,(c>>4)*4+3,vc(10));
13864 break;
13865 }
13866 }
13867
13868 void drawdmap_screen(int32_t x, int32_t y, int32_t w, int32_t h, int32_t dmap)
13869 {
13870 BITMAP *tempbmp = create_bitmap_ex(8,w,h);
13871 clear_to_color(tempbmp, vc(0));
13872 zcolors mc=QMisc.colors;
13873
13874 // rectfill(tempbmp,x,y,x+w-1,y+h-1,vc(0));
13875
13876 if(DMaps[dmap].minimap_2_tile)
13877 {
13878 draw_block(tempbmp,0,0,DMaps[dmap].minimap_2_tile,DMaps[dmap].minimap_2_cset,5,3);
13879 }
13880 else if(((DMaps[dmap].type&dmfTYPE)==dmDNGN || (DMaps[dmap].type&dmfTYPE)==dmCAVE) && mc.dungeon_map_tile)
13881 {
13882 draw_block(tempbmp,0,0,mc.dungeon_map_tile,mc.dungeon_map_cset,5,3);
13883 }
13884 else if(((DMaps[dmap].type&dmfTYPE)==dmOVERW || (DMaps[dmap].type&dmfTYPE)==dmBSOVERW) && mc.overworld_map_tile)
13885 {
13886 draw_block(tempbmp,0,0,mc.overworld_map_tile,mc.overworld_map_cset,5,3);
13887 }
13888
13889 masked_blit(dmapbmp_small,tempbmp,0,0,8,7,65,33);
13890
13891 blit(tempbmp,screen,0,0,x,y,w,h);
13892 destroy_bitmap(tempbmp);
13893
13894 }
13895
13896 int32_t d_dmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13897 {
13898 if(msg==MSG_DRAW)
13899 {
13900 int32_t dmap = d->d1;
13901 int32_t xy[6] = {44,92,128,100,128,110};
13902 //int32_t *xy = (int32_t*)(d->dp3);
13903 float temp_scale = 1.5;
13904
13905 drawdmap(dmap);
13906
13907 if(xy[0]>-1000&&xy[1]>-1000)
13908 {
13909 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13910 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13911 int32_t w = 84;
13912 int32_t h = 52;
13913 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13914 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13915 }
13916
13917 if(xy[2]>-1000&&xy[3]>-1000)
13918 {
13919 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13920 }
13921
13922 if(xy[4]>-1000&&xy[5]>-1000)
13923 {
13924 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13925 }
13926 }
13927
13928 return jwin_list_proc(msg,d,c);
13929 }
13930
13931 int32_t d_dropdmaplist_proc(int32_t msg,DIALOG *d,int32_t c)
13932 {
13933 if(msg==MSG_DRAW)
13934 {
13935 int32_t dmap = d->d1;
13936 int32_t *xy = (int32_t*)(d->dp3);
13937 float temp_scale = 1.5;
13938
13939 drawdmap(dmap);
13940
13941 if(xy[0]>-1000&&xy[1]>-1000)
13942 {
13943 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
13944 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
13945 int32_t w = 84;
13946 int32_t h = 52;
13947 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
13948 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
13949 }
13950
13951 if(xy[2]>-1000&&xy[3]>-1000)
13952 {
13953 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[2])*temp_scale),d->y+int32_t((xy[3])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %-3d",DMaps[d->d1].map+1);
13954 }
13955
13956 if(xy[4]>-1000&&xy[5]>-1000)
13957 {
13958 textprintf_ex(screen,get_zc_font(font_lfont_l),d->x+int32_t((xy[4])*temp_scale),d->y+int32_t((xy[5])*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level: %-3d",DMaps[d->d1].level);
13959 }
13960 }
13961
13962 return jwin_droplist_proc(msg,d,c);
13963 }
13964
13965 void drawxmap(ALLEGRO_BITMAP* dest, int32_t themap, int32_t xoff, bool large, int dx, int dy)
13966 {
13967 ALLEGRO_STATE old_state;
13968 al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP);
13969
13970 al_set_target_bitmap(dest);
13971 al_clear_to_color(al_map_rgba(0, 0, 0, 0));
13972
13973 int32_t cols = (large ? 8 : 16);
13974 int32_t col_width = large ? 22 : 11;
13975 int32_t dot_width = (large ? 6 : 4);
13976 int32_t dot_offset = (large ? 7 : 3);
13977 int32_t l = 10;
13978
13979 for (int32_t y = 0; y < 8; y++)
13980 {
13981 // Users might have set the dmap to a map that has since been deleted.
13982 if (themap >= Map.getMapCount())
13983 break;
13984
13985 for (int32_t x = 0; x < cols; x++)
13986 {
13987 if (x + xoff < 0 || x + xoff > 15)
13988 continue;
13989 mapscr* scr = &TheMaps[themap * MAPSCRS + y * 16 + x + (large ? xoff : 0)];
13990 if (!(scr->valid & mVALID))
13991 continue;
13992 al_draw_filled_rectangle(dx + (x * col_width), dy + (y * l), dx + (x * col_width + col_width), dy + ((y * l) + l), real_lc1(scr->color));
13993
13994 al_draw_filled_rectangle(dx + (x * col_width + dot_offset), dy + (y * l + 3), dx + (x * col_width + dot_offset + dot_width), dy + (y * l + l - 3), real_lc2(scr->color));
13995 }
13996 }
13997
13998 al_restore_state(&old_state);
13999 }
14000
14001 const char *dmapscriptdroplist(int32_t index, int32_t *list_size)
14002 {
14003 if(index<0)
14004 {
14005 *list_size = bidmaps_cnt;
14006 return NULL;
14007 }
14008
14009 return bidmaps[index].first.c_str();
14010 }
14011
14012
14013 //droplist like the dialog proc, naming scheme for this stuff is awful...
14014 9 static ListData dmapscript_list(dmapscriptdroplist, &a4fonts[font_pfont]);
14015
14016 //int32_t selectdmapxy[6] = {90,142,164,150,164,160};
14017 int32_t selectdmapxy[6] = {44,92,128,100,128,110};
14018
14019 9 static ListData dmap_list(dmaplist, &font);
14020
14021 static DIALOG selectdmap_dlg[] =
14022 {
14023 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
14024 9 { jwin_win_proc, 72-44, 56-30, 176+88+1, 120+74+1, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select DMap", NULL, NULL },
14025 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
14026 9 { d_dmaplist_proc, 46, 50, 64+72+88+1, 60+24+1+2, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &dmap_list, NULL, selectdmapxy },
14027 9 { jwin_button_proc, 90, 152+44, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
14028 9 { jwin_button_proc, 170, 152+44, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
14029 9 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_DEL, (void *) close_dlg, NULL, NULL },
14030 9 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_C, (void*)close_dlg, NULL, NULL },
14031 9 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_V, (void*)close_dlg, NULL, NULL },
14032 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
14033 };
14034
14035 9 static dmap copiedDMap;
14036 static byte dmapcopied = 0;
14037
14038 int32_t writesomedmaps(PACKFILE *f, int32_t first, int32_t last, int32_t max)
14039 {
14040
14041 dword section_version=V_DMAPS;
14042 dword section_cversion=CV_DMAPS;
14043 int32_t zversion = ZELDA_VERSION;
14044 int32_t zbuild = VERSION_BUILD;
14045
14046 if(!p_iputl(V_ZDMAP,f))
14047 {
14048 return 0;
14049 }
14050
14051 //section version info
14052 if(!p_iputl(zversion,f))
14053 {
14054 return 0;
14055 }
14056 if(!p_iputl(zbuild,f))
14057 {
14058 return 0;
14059 }
14060 if(!p_iputw(section_version,f))
14061 {
14062 new_return(2);
14063 }
14064
14065 if(!p_iputw(section_cversion,f))
14066 {
14067 new_return(3);
14068 }
14069 //max possible at this time
14070 if(!p_iputl(max,f))
14071 {
14072 new_return(4);
14073 }
14074 //first id written
14075 if(!p_iputl(first,f))
14076 {
14077 new_return(5);
14078 }
14079 //last id written
14080 if(!p_iputl(last,f))
14081 {
14082 new_return(6);
14083 }
14084 int32_t count = last-first;
14085 //number written
14086 if(!p_iputl(count,f))
14087 {
14088 new_return(7);
14089 }
14090
14091
14092 for ( int32_t i = first; i <= last; ++i )
14093 {
14094 if ( i > max ) break;
14095
14096 if(!p_putc(DMaps[i].map,f))
14097 {
14098 new_return(8);
14099 }
14100
14101 if(!p_iputw(DMaps[i].level,f))
14102 {
14103 new_return(9);
14104 }
14105
14106 if(!p_putc(DMaps[i].xoff,f))
14107 {
14108 new_return(10);
14109 }
14110
14111 if(!p_putc(DMaps[i].compass,f))
14112 {
14113 new_return(11);
14114 }
14115
14116 if(!p_iputw(DMaps[i].color,f))
14117 {
14118 new_return(12);
14119 }
14120
14121 if(!p_putc(DMaps[i].midi,f))
14122 {
14123 new_return(13);
14124 }
14125
14126 if(!p_putc(DMaps[i].cont,f))
14127 {
14128 new_return(14);
14129 }
14130
14131 if(!p_putc(DMaps[i].type,f))
14132 {
14133 new_return(15);
14134 }
14135
14136 for(int32_t j=0; j<8; j++)
14137 {
14138 if(!p_putc(DMaps[i].grid[j],f))
14139 {
14140 new_return(16);
14141 }
14142 }
14143
14144 //16
14145 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14146 {
14147 new_return(17);
14148 }
14149
14150 if(!p_putwstr(DMaps[i].title,f))
14151 {
14152 new_return(18);
14153 }
14154
14155 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14156 {
14157 new_return(19);
14158 }
14159
14160 if(!p_iputl(DMaps[i].minimap_1_tile,f))
14161 {
14162 new_return(20);
14163 }
14164
14165 if(!p_putc(DMaps[i].minimap_1_cset,f))
14166 {
14167 new_return(21);
14168 }
14169
14170 if(!p_iputl(DMaps[i].minimap_2_tile,f))
14171 {
14172 new_return(22);
14173 }
14174
14175 if(!p_putc(DMaps[i].minimap_2_cset,f))
14176 {
14177 new_return(23);
14178 }
14179
14180 if(!p_iputl(DMaps[i].largemap_1_tile,f))
14181 {
14182 new_return(24);
14183 }
14184
14185 if(!p_putc(DMaps[i].largemap_1_cset,f))
14186 {
14187 new_return(25);
14188 }
14189
14190 if(!p_iputl(DMaps[i].largemap_2_tile,f))
14191 {
14192 new_return(26);
14193 }
14194
14195 if(!p_putc(DMaps[i].largemap_2_cset,f))
14196 {
14197 new_return(27);
14198 }
14199
14200 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14201 {
14202 new_return(28);
14203 }
14204
14205 if(!p_putc(DMaps[i].tmusictrack,f))
14206 {
14207 new_return(29);
14208 }
14209
14210 if(!p_putc(DMaps[i].active_subscreen,f))
14211 {
14212 new_return(30);
14213 }
14214
14215 if(!p_putc(DMaps[i].passive_subscreen,f))
14216 {
14217 new_return(31);
14218 }
14219
14220 byte disabled[32];
14221 memset(disabled,0,32);
14222
14223 for(int32_t j=0; j<MAXITEMS; j++)
14224 {
14225 if(DMaps[i].disableditems[j])
14226 {
14227 disabled[j/8] |= (1 << (j%8));
14228 }
14229 }
14230
14231 if(!pfwrite(disabled,32,f))
14232 {
14233 new_return(32);
14234 }
14235
14236 if(!p_iputl(DMaps[i].flags,f))
14237 {
14238 new_return(33);
14239 }
14240 if(!p_putc(DMaps[i].sideview,f))
14241 {
14242 new_return(30);
14243 }
14244 if(!p_iputw(DMaps[i].script,f))
14245 {
14246 new_return(31);
14247 }
14248 for ( int32_t q = 0; q < 8; q++ )
14249 {
14250 if(!p_iputl(DMaps[i].initD[q],f))
14251 {
14252 new_return(32);
14253 }
14254
14255 }
14256 for ( int32_t q = 0; q < 8; q++ )
14257 {
14258 for ( int32_t w = 0; w < 65; w++ )
14259 {
14260 if (!p_putc(DMaps[i].initD_label[q][w],f))
14261 {
14262 new_return(33);
14263 }
14264 }
14265 }
14266 if(!p_iputw(DMaps[i].active_sub_script,f))
14267 {
14268 new_return(34);
14269 }
14270 if(!p_iputw(DMaps[i].passive_sub_script,f))
14271 {
14272 new_return(35);
14273 }
14274 for(int32_t q = 0; q < 8; ++q)
14275 {
14276 if(!p_iputl(DMaps[i].sub_initD[q],f))
14277 {
14278 new_return(36);
14279 }
14280 }
14281 for(int32_t q = 0; q < 8; ++q)
14282 {
14283 for(int32_t w = 0; w < 65; ++w)
14284 {
14285 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14286 {
14287 new_return(37);
14288 }
14289 }
14290 }
14291 if(!p_iputw(DMaps[i].onmap_script,f))
14292 {
14293 new_return(35);
14294 }
14295 for(int32_t q = 0; q < 8; ++q)
14296 {
14297 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14298 {
14299 new_return(36);
14300 }
14301 }
14302 for(int32_t q = 0; q < 8; ++q)
14303 {
14304 for(int32_t w = 0; w < 65; ++w)
14305 {
14306 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14307 {
14308 new_return(37);
14309 }
14310 }
14311 }
14312 if (!p_iputw(DMaps[i].mirrorDMap, f))
14313 {
14314 new_return(38);
14315 }
14316 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14317 {
14318 new_return(39);
14319 }
14320 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14321 {
14322 new_return(40);
14323 }
14324 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14325 {
14326 new_return(41);
14327 }
14328 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14329 {
14330 new_return(42);
14331 }
14332 }
14333
14334 return 1;
14335 }
14336
14337
14338 int32_t readsomedmaps(PACKFILE *f)
14339 {
14340 dword section_version = 0;
14341 dword section_cversion = 0;
14342 int32_t zversion = 0;
14343 int32_t zbuild = 0;
14344 dmap tempdmap{};
14345
14346 int32_t first = 0, last = 0, max = 0, count = 0;
14347 int32_t datatype_version = 0;
14348
14349 //char dmapstring[64]={0};
14350 //section version info
14351 if(!p_igetl(&datatype_version,f))
14352 {
14353 return 0;
14354 }
14355 if ( datatype_version < 0 )
14356 {
14357 if(!p_igetl(&zversion,f))
14358 {
14359 return 0;
14360 }
14361 }
14362 else
14363 {
14364 zversion = datatype_version;
14365 }
14366 if(!p_igetl(&zbuild,f))
14367 {
14368 return 0;
14369 }
14370
14371 if(!p_igetw(&section_version,f))
14372 {
14373 return 0;
14374 }
14375
14376 if(!p_igetw(&section_cversion,f))
14377 {
14378 return 0;
14379 }
14380 if ( datatype_version < 0 )
14381 {
14382 if(!p_igetl(&max,f))
14383 {
14384 return 0;
14385 }
14386 if(!p_igetl(&first,f))
14387 {
14388 return 0;
14389 }
14390 if(!p_igetl(&last,f))
14391 {
14392 return 0;
14393 }
14394 if(!p_igetl(&count,f))
14395 {
14396 return 0;
14397 }
14398 }
14399 else
14400 {
14401 first = 0;
14402 last = 0;
14403 count = 1;
14404 max = 255;
14405 }
14406
14407
14408
14409
14410 al_trace("readsomedmaps section_version: %d\n", section_version);
14411 al_trace("readsomedmaps section_cversion: %d\n", section_cversion);
14412
14413 if ( zversion > ZELDA_VERSION )
14414 {
14415 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
14416 return 0;
14417 }
14418 else if (( section_version > V_DMAPS ) || ( section_version == V_DMAPS && section_cversion > CV_DMAPS ) )
14419 {
14420 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d) subversion (%d)\n", section_version, section_cversion);
14421 return 0;
14422 }
14423 else
14424 {
14425 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
14426 }
14427 //if(!pfread(&dmapstring, 64, f))
14428 //{
14429 // return 0;
14430 //}
14431
14432
14433
14434 for ( int32_t i = first; i <= last; ++i )
14435 {
14436 if(!p_getc(&tempdmap.map,f))
14437 {
14438 return 0;
14439 }
14440
14441 if(!p_igetw(&tempdmap.level,f))
14442 {
14443 return 0;
14444 }
14445
14446 if(!p_getc(&tempdmap.xoff,f))
14447 {
14448 return 0;
14449 }
14450
14451 if(!p_getc(&tempdmap.compass,f))
14452 {
14453 return 0;
14454 }
14455
14456 if(!p_igetw(&tempdmap.color,f))
14457 {
14458 return 0;
14459 }
14460
14461 if(!p_getc(&tempdmap.midi,f))
14462 {
14463 return 0;
14464 }
14465
14466 if(!p_getc(&tempdmap.cont,f))
14467 {
14468 return 0;
14469 }
14470
14471 if(!p_getc(&tempdmap.type,f))
14472 {
14473 return 0;
14474 }
14475
14476 for(int32_t j=0; j<8; j++)
14477 {
14478 if(!p_getc(&tempdmap.grid[j],f))
14479 {
14480 return 0;
14481 }
14482 }
14483
14484 //16
14485 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
14486 {
14487 return 0;
14488 }
14489
14490 if (section_version<20)
14491 {
14492 char title[22];
14493 if (!p_getstr(title, sizeof(title) - 1, f))
14494 {
14495 return 0;
14496 }
14497 tempdmap.title.assign(title);
14498 }
14499 else
14500 {
14501 if (!p_getwstr(&tempdmap.title, f))
14502 {
14503 return 0;
14504 }
14505 }
14506
14507 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
14508 {
14509 return 0;
14510 }
14511
14512 if(!p_igetl(&tempdmap.minimap_1_tile,f))
14513 {
14514 return 0;
14515 }
14516
14517 if(!p_getc(&tempdmap.minimap_1_cset,f))
14518 {
14519 return 0;
14520 }
14521
14522 if(!p_igetl(&tempdmap.minimap_2_tile,f))
14523 {
14524 return 0;
14525 }
14526
14527 if(!p_getc(&tempdmap.minimap_2_cset,f))
14528 {
14529 return 0;
14530 }
14531
14532 if(!p_igetl(&tempdmap.largemap_1_tile,f))
14533 {
14534 return 0;
14535 }
14536
14537 if(!p_getc(&tempdmap.largemap_1_cset,f))
14538 {
14539 return 0;
14540 }
14541
14542 if(!p_igetl(&tempdmap.largemap_2_tile,f))
14543 {
14544 return 0;
14545 }
14546
14547 if(!p_getc(&tempdmap.largemap_2_cset,f))
14548 {
14549 return 0;
14550 }
14551
14552 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
14553 {
14554 return 0;
14555 }
14556
14557 if(!p_getc(&tempdmap.tmusictrack,f))
14558 {
14559 return 0;
14560 }
14561
14562 if(!p_getc(&tempdmap.active_subscreen,f))
14563 {
14564 return 0;
14565 }
14566
14567 if(!p_getc(&tempdmap.passive_subscreen,f))
14568 {
14569 return 0;
14570 }
14571
14572 byte disabled[32];
14573 memset(disabled,0,32);
14574
14575 if(!pfread(&disabled, 32, f)) return 0;
14576
14577 for(int32_t j=0; j<MAXITEMS; j++)
14578 {
14579 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
14580 else tempdmap.disableditems[j]=0;
14581 }
14582
14583
14584 if(!p_igetl(&tempdmap.flags,f))
14585 {
14586 return 0;
14587 }
14588 if ( zversion >= 0x255 )
14589 {
14590 if ( section_version >= 14 )
14591 {
14592 //2.55 starts here
14593 if(!p_getc(&tempdmap.sideview,f))
14594 {
14595 return 0;
14596 }
14597 if(!p_igetw(&tempdmap.script,f))
14598 {
14599 return 0;
14600 }
14601 for ( int32_t q = 0; q < 8; q++ )
14602 {
14603 if(!p_igetl(&tempdmap.initD[q],f))
14604 {
14605 return 0;
14606 }
14607
14608 }
14609 for ( int32_t q = 0; q < 8; q++ )
14610 {
14611 for ( int32_t w = 0; w < 65; w++ )
14612 {
14613 if (!p_getc(&tempdmap.initD_label[q][w],f))
14614 {
14615 return 0;
14616 }
14617 }
14618 }
14619 if(!p_igetw(&tempdmap.active_sub_script,f))
14620 {
14621 return 0;
14622 }
14623 if(!p_igetw(&tempdmap.passive_sub_script,f))
14624 {
14625 return 0;
14626 }
14627 for(int32_t q = 0; q < 8; ++q)
14628 {
14629 if(!p_igetl(&tempdmap.sub_initD[q],f))
14630 {
14631 return 0;
14632 }
14633 }
14634 for(int32_t q = 0; q < 8; ++q)
14635 {
14636 for(int32_t w = 0; w < 65; ++w)
14637 {
14638 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
14639 {
14640 return 0;
14641 }
14642 }
14643 }
14644 if(!p_igetw(&tempdmap.onmap_script,f))
14645 {
14646 return 0;
14647 }
14648 for(int32_t q = 0; q < 8; ++q)
14649 {
14650 if(!p_igetl(&tempdmap.onmap_initD[q],f))
14651 {
14652 return 0;
14653 }
14654 }
14655 for(int32_t q = 0; q < 8; ++q)
14656 {
14657 for(int32_t w = 0; w < 65; ++w)
14658 {
14659 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
14660 {
14661 return 0;
14662 }
14663 }
14664 }
14665 if (!p_igetw(&tempdmap.mirrorDMap, f))
14666 {
14667 return 0;
14668 }
14669 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
14670 {
14671 return 0;
14672 }
14673 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
14674 {
14675 return 0;
14676 }
14677 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
14678 {
14679 return 0;
14680 }
14681 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
14682 {
14683 return 0;
14684 }
14685 }
14686 }
14687 DMaps[i].clear();
14688 DMaps[i] = tempdmap;
14689 }
14690
14691 return 1;
14692 }
14693
14694
14695
14696 int32_t writeonedmap(PACKFILE *f, int32_t i)
14697 {
14698
14699 dword section_version=V_DMAPS;
14700 dword section_cversion=CV_DMAPS;
14701 int32_t zversion = ZELDA_VERSION;
14702 int32_t zbuild = VERSION_BUILD;
14703
14704
14705 //section version info
14706 if(!p_iputl(V_ZDMAP,f))
14707 {
14708 return 0;
14709 }
14710 if(!p_iputl(zversion,f))
14711 {
14712 return 0;
14713 }
14714 if(!p_iputl(zbuild,f))
14715 {
14716 return 0;
14717 }
14718 if(!p_iputw(section_version,f))
14719 {
14720 new_return(2);
14721 }
14722
14723 if(!p_iputw(section_cversion,f))
14724 {
14725 new_return(3);
14726 }
14727
14728
14729
14730 if(!p_putc(DMaps[i].map,f))
14731 {
14732 new_return(6);
14733 }
14734
14735 if(!p_iputw(DMaps[i].level,f))
14736 {
14737 new_return(7);
14738 }
14739
14740 if(!p_putc(DMaps[i].xoff,f))
14741 {
14742 new_return(8);
14743 }
14744
14745 if(!p_putc(DMaps[i].compass,f))
14746 {
14747 new_return(9);
14748 }
14749
14750 if(!p_iputw(DMaps[i].color,f))
14751 {
14752 new_return(10);
14753 }
14754
14755 if(!p_putc(DMaps[i].midi,f))
14756 {
14757 new_return(11);
14758 }
14759
14760 if(!p_putc(DMaps[i].cont,f))
14761 {
14762 new_return(12);
14763 }
14764
14765 if(!p_putc(DMaps[i].type,f))
14766 {
14767 new_return(13);
14768 }
14769
14770 for(int32_t j=0; j<8; j++)
14771 {
14772 if(!p_putc(DMaps[i].grid[j],f))
14773 {
14774 new_return(14);
14775 }
14776 }
14777
14778 //16
14779 if(!pfwrite(&DMaps[i].name,sizeof(DMaps[0].name),f))
14780 {
14781 new_return(15);
14782 }
14783
14784 if(!pfwrite(&DMaps[i].title,sizeof(DMaps[0].title),f))
14785 {
14786 new_return(16);
14787 }
14788
14789 if(!pfwrite(&DMaps[i].intro,sizeof(DMaps[0].intro),f))
14790 {
14791 new_return(17);
14792 }
14793
14794 if(!p_iputl(DMaps[i].minimap_1_tile,f))
14795 {
14796 new_return(18);
14797 }
14798
14799 if(!p_putc(DMaps[i].minimap_1_cset,f))
14800 {
14801 new_return(19);
14802 }
14803
14804 if(!p_iputl(DMaps[i].minimap_2_tile,f))
14805 {
14806 new_return(20);
14807 }
14808
14809 if(!p_putc(DMaps[i].minimap_2_cset,f))
14810 {
14811 new_return(21);
14812 }
14813
14814 if(!p_iputl(DMaps[i].largemap_1_tile,f))
14815 {
14816 new_return(22);
14817 }
14818
14819 if(!p_putc(DMaps[i].largemap_1_cset,f))
14820 {
14821 new_return(23);
14822 }
14823
14824 if(!p_iputl(DMaps[i].largemap_2_tile,f))
14825 {
14826 new_return(24);
14827 }
14828
14829 if(!p_putc(DMaps[i].largemap_2_cset,f))
14830 {
14831 new_return(25);
14832 }
14833
14834 if(!pfwrite(&DMaps[i].tmusic,sizeof(DMaps[0].tmusic),f))
14835 {
14836 new_return(26);
14837 }
14838
14839 if(!p_putc(DMaps[i].tmusictrack,f))
14840 {
14841 new_return(25);
14842 }
14843
14844 if(!p_putc(DMaps[i].active_subscreen,f))
14845 {
14846 new_return(26);
14847 }
14848
14849 if(!p_putc(DMaps[i].passive_subscreen,f))
14850 {
14851 new_return(27);
14852 }
14853
14854 byte disabled[32];
14855 memset(disabled,0,32);
14856
14857 for(int32_t j=0; j<MAXITEMS; j++)
14858 {
14859 if(DMaps[i].disableditems[j])
14860 {
14861 disabled[j/8] |= (1 << (j%8));
14862 }
14863 }
14864
14865 if(!pfwrite(disabled,32,f))
14866 {
14867 new_return(28);
14868 }
14869
14870 if(!p_iputl(DMaps[i].flags,f))
14871 {
14872 new_return(29);
14873 }
14874 if(!p_putc(DMaps[i].sideview,f))
14875 {
14876 new_return(30);
14877 }
14878 if(!p_iputw(DMaps[i].script,f))
14879 {
14880 new_return(31);
14881 }
14882 for ( int32_t q = 0; q < 8; q++ )
14883 {
14884 if(!p_iputl(DMaps[i].initD[q],f))
14885 {
14886 new_return(32);
14887 }
14888
14889 }
14890 for ( int32_t q = 0; q < 8; q++ )
14891 {
14892 for ( int32_t w = 0; w < 65; w++ )
14893 {
14894 if (!p_putc(DMaps[i].initD_label[q][w],f))
14895 {
14896 new_return(33);
14897 }
14898 }
14899 }
14900 if(!p_iputw(DMaps[i].active_sub_script,f))
14901 {
14902 new_return(34);
14903 }
14904 if(!p_iputw(DMaps[i].passive_sub_script,f))
14905 {
14906 new_return(35);
14907 }
14908 for(int32_t q = 0; q < 8; ++q)
14909 {
14910 if(!p_iputl(DMaps[i].sub_initD[q],f))
14911 {
14912 new_return(36);
14913 }
14914 }
14915 for(int32_t q = 0; q < 8; ++q)
14916 {
14917 for(int32_t w = 0; w < 65; ++w)
14918 {
14919 if(!p_putc(DMaps[i].sub_initD_label[q][w],f))
14920 {
14921 new_return(37);
14922 }
14923 }
14924 }
14925 if(!p_iputw(DMaps[i].onmap_script,f))
14926 {
14927 new_return(35);
14928 }
14929 for(int32_t q = 0; q < 8; ++q)
14930 {
14931 if(!p_iputl(DMaps[i].onmap_initD[q],f))
14932 {
14933 new_return(36);
14934 }
14935 }
14936 for(int32_t q = 0; q < 8; ++q)
14937 {
14938 for(int32_t w = 0; w < 65; ++w)
14939 {
14940 if(!p_putc(DMaps[i].onmap_initD_label[q][w],f))
14941 {
14942 new_return(37);
14943 }
14944 }
14945 }
14946 if (!p_iputw(DMaps[i].mirrorDMap, f))
14947 {
14948 new_return(38);
14949 }
14950 if (!p_iputl(DMaps[i].tmusic_loop_start, f))
14951 {
14952 new_return(39);
14953 }
14954 if (!p_iputl(DMaps[i].tmusic_loop_end, f))
14955 {
14956 new_return(40);
14957 }
14958 if (!p_iputl(DMaps[i].tmusic_xfade_in, f))
14959 {
14960 new_return(41);
14961 }
14962 if (!p_iputl(DMaps[i].tmusic_xfade_out, f))
14963 {
14964 new_return(42);
14965 }
14966
14967 return 1;
14968 }
14969
14970
14971 int32_t readonedmap(PACKFILE *f, int32_t index)
14972 {
14973 dword section_version = 0;
14974 dword section_cversion = 0;
14975 int32_t zversion = 0;
14976 int32_t zbuild = 0;
14977 dmap tempdmap{};
14978 int32_t datatype_version = 0;
14979 int32_t first = 0;
14980 int32_t last = 0;
14981 int32_t max = 0;
14982 int32_t count = 0;
14983
14984 //char dmapstring[64]={0};
14985 //section version info
14986 if(!p_igetl(&datatype_version,f))
14987 {
14988 return 0;
14989 }
14990 if ( datatype_version < 0 )
14991 {
14992 if(!p_igetl(&zversion,f))
14993 {
14994 return 0;
14995 }
14996 }
14997 else
14998 {
14999 zversion = datatype_version;
15000 }
15001 if(!p_igetl(&zbuild,f))
15002 {
15003 return 0;
15004 }
15005
15006 if(!p_igetw(&section_version,f))
15007 {
15008 return 0;
15009 }
15010
15011 if(!p_igetw(&section_cversion,f))
15012 {
15013 return 0;
15014 }
15015 al_trace("readonedmap section_version: %d\n", section_version);
15016 al_trace("readonedmap section_cversion: %d\n", section_cversion);
15017
15018
15019 if ( datatype_version < 0 )
15020 {
15021 if(!p_igetl(&max,f))
15022 {
15023 return 0;
15024 }
15025 if(!p_igetl(&first,f))
15026 {
15027 return 0;
15028 }
15029 if(!p_igetl(&last,f))
15030 {
15031 return 0;
15032 }
15033 if(!p_igetl(&count,f))
15034 {
15035 return 0;
15036 }
15037 }
15038 if ( zversion > ZELDA_VERSION )
15039 {
15040 al_trace("Cannot read .zdmap packfile made in ZC version (%x) in this version of ZC (%x)\n", zversion, ZELDA_VERSION);
15041 return 0;
15042 }
15043 else if (( section_version > V_DMAPS ) || ( section_version == V_DMAPS && section_cversion > CV_DMAPS ) )
15044 {
15045 al_trace("Cannot read .zdmap packfile made using V_DMAPS (%d) subversion (%d)\n", section_version, section_cversion);
15046 return 0;
15047 }
15048 else
15049 {
15050 al_trace("Reading a .zdmap packfile made in ZC Version: %x, Build: %d\n", zversion, zbuild);
15051 }
15052 //if(!pfread(&dmapstring, 64, f))
15053 //{
15054 // return 0;
15055 //}
15056
15057
15058
15059
15060 if(!p_getc(&tempdmap.map,f))
15061 {
15062 return 0;
15063 }
15064
15065 if(!p_igetw(&tempdmap.level,f))
15066 {
15067 return 0;
15068 }
15069
15070 if(!p_getc(&tempdmap.xoff,f))
15071 {
15072 return 0;
15073 }
15074
15075 if(!p_getc(&tempdmap.compass,f))
15076 {
15077 return 0;
15078 }
15079
15080 if(!p_igetw(&tempdmap.color,f))
15081 {
15082 return 0;
15083 }
15084
15085 if(!p_getc(&tempdmap.midi,f))
15086 {
15087 return 0;
15088 }
15089
15090 if(!p_getc(&tempdmap.cont,f))
15091 {
15092 return 0;
15093 }
15094
15095 if(!p_getc(&tempdmap.type,f))
15096 {
15097 return 0;
15098 }
15099
15100 for(int32_t j=0; j<8; j++)
15101 {
15102 if(!p_getc(&tempdmap.grid[j],f))
15103 {
15104 return 0;
15105 }
15106 }
15107
15108 //16
15109 if(!pfread(&tempdmap.name,sizeof(DMaps[0].name),f))
15110 {
15111 return 0;
15112 }
15113
15114 if (section_version<20)
15115 {
15116 char title[22];
15117 if (!p_getstr(title, sizeof(title) - 1, f))
15118 {
15119 return 0;
15120 }
15121 tempdmap.title.assign(title);
15122 }
15123 else
15124 {
15125 if (!p_getwstr(&tempdmap.title, f))
15126 {
15127 return 0;
15128 }
15129 }
15130
15131 if(!pfread(&tempdmap.title,sizeof(DMaps[0].title),f))
15132 {
15133 return 0;
15134 }
15135
15136 if(!pfread(&tempdmap.intro,sizeof(DMaps[0].intro),f))
15137 {
15138 return 0;
15139 }
15140
15141 if(!p_igetl(&tempdmap.minimap_1_tile,f))
15142 {
15143 return 0;
15144 }
15145
15146 if(!p_getc(&tempdmap.minimap_1_cset,f))
15147 {
15148 return 0;
15149 }
15150
15151 if(!p_igetl(&tempdmap.minimap_2_tile,f))
15152 {
15153 return 0;
15154 }
15155
15156 if(!p_getc(&tempdmap.minimap_2_cset,f))
15157 {
15158 return 0;
15159 }
15160
15161 if(!p_igetl(&tempdmap.largemap_1_tile,f))
15162 {
15163 return 0;
15164 }
15165
15166 if(!p_getc(&tempdmap.largemap_1_cset,f))
15167 {
15168 return 0;
15169 }
15170
15171 if(!p_igetl(&tempdmap.largemap_2_tile,f))
15172 {
15173 return 0;
15174 }
15175
15176 if(!p_getc(&tempdmap.largemap_2_cset,f))
15177 {
15178 return 0;
15179 }
15180
15181 if(!pfread(&tempdmap.tmusic,sizeof(DMaps[0].tmusic),f))
15182 {
15183 return 0;
15184 }
15185
15186 if(!p_getc(&tempdmap.tmusictrack,f))
15187 {
15188 return 0;
15189 }
15190
15191 if(!p_getc(&tempdmap.active_subscreen,f))
15192 {
15193 return 0;
15194 }
15195
15196 if(!p_getc(&tempdmap.passive_subscreen,f))
15197 {
15198 return 0;
15199 }
15200
15201 byte disabled[32];
15202 memset(disabled,0,32);
15203
15204 if(!pfread(&disabled, 32, f)) return 0;
15205
15206 for(int32_t j=0; j<MAXITEMS; j++)
15207 {
15208 if(disabled[j/8] & (1 << (j%8))) tempdmap.disableditems[j]=1;
15209 else tempdmap.disableditems[j]=0;
15210 }
15211
15212
15213 if(!p_igetl(&tempdmap.flags,f))
15214 {
15215 return 0;
15216 }
15217 if ( zversion >= 0x255 )
15218 {
15219 if ( section_version >= 14 )
15220 {
15221 //2.55 starts here
15222 if(!p_getc(&tempdmap.sideview,f))
15223 {
15224 return 0;
15225 }
15226 if(!p_igetw(&tempdmap.script,f))
15227 {
15228 return 0;
15229 }
15230 for ( int32_t q = 0; q < 8; q++ )
15231 {
15232 if(!p_igetl(&tempdmap.initD[q],f))
15233 {
15234 return 0;
15235 }
15236
15237 }
15238 for ( int32_t q = 0; q < 8; q++ )
15239 {
15240 for ( int32_t w = 0; w < 65; w++ )
15241 {
15242 if (!p_getc(&tempdmap.initD_label[q][w],f))
15243 {
15244 return 0;
15245 }
15246 }
15247 }
15248 if(!p_igetw(&tempdmap.active_sub_script,f))
15249 {
15250 return 0;
15251 }
15252 if(!p_igetw(&tempdmap.passive_sub_script,f))
15253 {
15254 return 0;
15255 }
15256 for(int32_t q = 0; q < 8; ++q)
15257 {
15258 if(!p_igetl(&tempdmap.sub_initD[q],f))
15259 {
15260 return 0;
15261 }
15262 }
15263 for(int32_t q = 0; q < 8; ++q)
15264 {
15265 for(int32_t w = 0; w < 65; ++w)
15266 {
15267 if(!p_getc(&tempdmap.sub_initD_label[q][w],f))
15268 {
15269 return 0;
15270 }
15271 }
15272 }
15273 if(!p_igetw(&tempdmap.onmap_script,f))
15274 {
15275 return 0;
15276 }
15277 for(int32_t q = 0; q < 8; ++q)
15278 {
15279 if(!p_igetl(&tempdmap.onmap_initD[q],f))
15280 {
15281 return 0;
15282 }
15283 }
15284 for(int32_t q = 0; q < 8; ++q)
15285 {
15286 for(int32_t w = 0; w < 65; ++w)
15287 {
15288 if(!p_getc(&tempdmap.onmap_initD_label[q][w],f))
15289 {
15290 return 0;
15291 }
15292 }
15293 }
15294 if (!p_igetw(&tempdmap.mirrorDMap, f))
15295 {
15296 return 0;
15297 }
15298 if (!p_igetl(&tempdmap.tmusic_loop_start, f))
15299 {
15300 return 0;
15301 }
15302 if (!p_igetl(&tempdmap.tmusic_loop_end, f))
15303 {
15304 return 0;
15305 }
15306 if (!p_igetl(&tempdmap.tmusic_xfade_in, f))
15307 {
15308 return 0;
15309 }
15310 if (!p_igetl(&tempdmap.tmusic_xfade_out, f))
15311 {
15312 return 0;
15313 }
15314 }
15315 }
15316 DMaps[index] = tempdmap;
15317
15318 return 1;
15319 }
15320
15321 void dmap_rclick_func(int32_t index, int32_t x, int32_t y)
15322 {
15323 if(((unsigned)index)>MAXDMAPS)
15324 return;
15325
15326 NewMenu rcmenu {
15327 { "&Copy", [&]()
15328 {
15329 copiedDMap = DMaps[index];
15330 dmapcopied = 1;
15331 } },
15332 { "Paste", "&v", [&]()
15333 {
15334 DMaps[index] = copiedDMap;
15335 selectdmap_dlg[2].flags |= D_DIRTY;
15336 saved = false;
15337 }, 0, !dmapcopied },
15338 { "&Save", [&]()
15339 {
15340 if(!prompt_for_new_file_compat("Save DMAP(.zdmap)", "zdmap", NULL,datapath,false))
15341 return;
15342 PACKFILE *f=pack_fopen_password(temppath,F_WRITE, "");
15343 if(!f) return;
15344 writesomedmaps(f,index, index, MAXDMAPS);
15345 pack_fclose(f);
15346 } },
15347 { "&Load", [&]()
15348 {
15349 if(!prompt_for_existing_file_compat("Load DMAP(.zdmap)", "zdmap", NULL,datapath,false))
15350 return;
15351 PACKFILE *f=pack_fopen_password(temppath,F_READ, "");
15352 if(!f) return;
15353
15354 if (!readonedmap(f,index))
15355 {
15356 al_trace("Could not read from .zdmap packfile %s\n", temppath);
15357 jwin_alert("ZDMAP File: Error","Could not load the specified DMap.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
15358 }
15359
15360 pack_fclose(f);
15361 selectdmap_dlg[2].flags |= D_DIRTY; //Causes the dialogie list to refresh, updating the item name.
15362 saved = false;
15363 } },
15364 };
15365 rcmenu.pop(x, y);
15366 }
15367
15368
15369 int32_t onDmaps()
15370 {
15371 int32_t ret;
15372 char buf[40];
15373 dmapcopied = 0;
15374 dmap_list_size=MAXDMAPS;
15375 number_list_zero=true;
15376 selectdmap_dlg[0].dp2=get_zc_font(font_lfont);
15377 selectdmap_dlg[2].dp3 = (void *)&dmap_rclick_func;
15378 selectdmap_dlg[2].flags|=(D_USER<<1);
15379
15380 large_dialog(selectdmap_dlg);
15381
15382
15383
15384 ret=do_zqdialog(selectdmap_dlg,2);
15385 dmap* pSelectedDmap = 0;
15386
15387
15388
15389 while(ret!=4&&ret!=0)
15390 {
15391 int32_t d=selectdmap_dlg[2].d1;
15392
15393 if(ret==6) //copy
15394 {
15395 pSelectedDmap = &DMaps[d];
15396 }
15397 else if(ret==7 && pSelectedDmap != 0 ) //paste
15398 {
15399 if( pSelectedDmap != &DMaps[d] )
15400 {
15401 DMaps[d] = *pSelectedDmap;
15402 saved=false;
15403 }
15404 }
15405 else if(ret==5)
15406 {
15407 sprintf(buf,"Delete DMap %d?",d);
15408
15409 if(jwin_alert("Confirm Delete",buf,NULL,NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
15410 {
15411 reset_dmap(d);
15412 saved=false;
15413 }
15414 }
15415 else
15416 {
15417 call_editdmap_dialog(d);
15418 }
15419
15420 ret=do_zqdialog(selectdmap_dlg,2);
15421 }
15422
15423 return D_O_K;
15424 }
15425
15426 int32_t onMidis()
15427 {
15428 stopMusic();
15429 MidiListerDialog().show();
15430 return D_O_K;
15431 }
15432
15433 static DIALOG editmusic_dlg[] =
15434 {
15435 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15436 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Music Specs", NULL, NULL },
15437 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15438 // 2
15439 { jwin_text_proc, 56, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Music:", NULL, NULL },
15440 { jwin_text_proc, 104, 94-16, 48, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15441 { jwin_text_proc, 56, 114, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
15442 { jwin_edit_proc, 104, 114-4, 160, 16, vc(12), vc(1), 0, 0, 19, 0, NULL, NULL, NULL },
15443 { jwin_text_proc, 56, 124-4+12, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Volume:", NULL, NULL },
15444 { jwin_edit_proc, 120, 124-4+12-4, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
15445 // 8
15446 { jwin_check_proc, 176, 124+12-4, 80+1, 8+1, vc(14), vc(1), 0, 0, 1, 0, (void *) "Loop", NULL, NULL },
15447 // 9
15448 { jwin_button_proc, 50, 72-24, 57, 21, vc(14), vc(1), 'l', D_EXIT, 0, 0, (void *) "&Load", NULL, NULL },
15449 { jwin_iconbutton_proc, 116, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_STOPSQUARE, 0, NULL, NULL, NULL },
15450 { jwin_iconbutton_proc, 156, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT, 0, NULL, NULL, NULL },
15451 { jwin_iconbutton_proc, 196, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT2, 0, NULL, NULL, NULL },
15452 { jwin_iconbutton_proc, 236, 72-24, 33, 21, vc(14), vc(1), 0, D_EXIT, BTNICON_ARROW_RIGHT3, 0, NULL, NULL, NULL },
15453 // 14
15454 { jwin_text_proc, 56, 134+4+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Start:", NULL, NULL },
15455 { jwin_edit_proc, 112, 134+12, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15456 { jwin_text_proc, 176, 134+12+4, 56, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop Start:", NULL, NULL },
15457 { jwin_edit_proc, 240, 134+12, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15458 { jwin_text_proc, 176, 144+12+12, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Loop End:", NULL, NULL },
15459 { jwin_edit_proc, 240, 144+12+12-4, 40, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
15460 // 20
15461 { jwin_text_proc, 176, 94-16, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Position:", NULL, NULL },
15462 { jwin_text_proc, 217, 94-16, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15463 { jwin_text_proc, 176, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Length:", NULL, NULL },
15464 { jwin_text_proc, 216, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15465 { jwin_text_proc, 56, 104-8, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Time:", NULL, NULL },
15466 { jwin_text_proc, 104, 104-8, 32, 8, vc(11), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
15467 // 26
15468 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15469 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15470 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
15471 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15472 };
15473
15474 int32_t d_musiclist_proc(int32_t msg,DIALOG *d,int32_t c)
15475 {
15476 return jwin_list_proc(msg,d,c);
15477 }
15478
15479 9 static ListData enhancedmusic_list(enhancedmusiclist, &font);
15480
15481 static DIALOG selectmusic_dlg[] =
15482 {
15483 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15484 9 { jwin_win_proc, 24, 20, 273, 189, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Select Enhanced Music", NULL, NULL },
15485 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15486 9 { d_musiclist_proc, 31, 44, 164, (1+16)*8, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &enhancedmusic_list, NULL, NULL },
15487 9 { jwin_button_proc, 90, 160+12+12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
15488 9 { jwin_button_proc, 170, 160+12+12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
15489 9 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, KEY_DEL, (void *) close_dlg, NULL, NULL },
15490 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15491 };
15492
15493 const char *warptypelist(int32_t index, int32_t *list_size)
15494 {
15495 if(index>=0)
15496 {
15497 if(index>=MAXWARPTYPES)
15498 index=MAXWARPTYPES-1;
15499
15500 return warptype_string[index];
15501 }
15502
15503 *list_size=MAXWARPTYPES;
15504 // *list_size=6;
15505 return NULL;
15506 }
15507
15508 const char *warpeffectlist(int32_t index, int32_t *list_size)
15509 {
15510 if(index>=0)
15511 {
15512 if(index>=MAXWARPEFFECTS)
15513 index=MAXWARPEFFECTS-1;
15514
15515 return warpeffect_string[index];
15516 }
15517
15518 *list_size=MAXWARPEFFECTS;
15519 return NULL;
15520 }
15521
15522 static int32_t warp1_list[] =
15523 {
15524 2,3,4,5,6,7,8,9,10,11,12,13,53,54,63,67,-1
15525 };
15526
15527 static int32_t warp2_list[] =
15528 {
15529 17,18,19,20,21,22,23,24,25,26,27,28,55,56,64,68,-1
15530 };
15531
15532 static int32_t warp3_list[] =
15533 {
15534 29,30,31,32,33,34,35,36,37,38,39,40,57,58,65,69,-1
15535 };
15536
15537 static int32_t warp4_list[] =
15538 {
15539 41,42,43,44,45,46,47,48,49,50,51,52,59,60,66,70,-1
15540 };
15541
15542 static TABPANEL warp_tabs[] =
15543 {
15544 // (text)
15545 { (char *)"A", D_SELECTED, warp1_list, 0, NULL },
15546 { (char *)"B", 0, warp2_list, 0, NULL },
15547 { (char *)"C", 0, warp3_list, 0, NULL },
15548 { (char *)"D", 0, warp4_list, 0, NULL },
15549 { NULL, 0, NULL, 0, NULL }
15550 };
15551
15552 int32_t onTileWarpIndex(int32_t index)
15553 {
15554 int32_t i=-1;
15555
15556 while(warp_tabs[++i].text != NULL)
15557 warp_tabs[i].flags = (i==index ? D_SELECTED : 0);
15558
15559 onTileWarp();
15560 return D_O_K;
15561 }
15562
15563 static char warpr_buf[10];
15564 const char *warprlist(int32_t index, int32_t *list_size)
15565 {
15566 if(index>=0)
15567 {
15568 bound(index,0,3);
15569 sprintf(warpr_buf,"%c",index+0x41);
15570 return warpr_buf;
15571 }
15572
15573 *list_size=4;
15574 return NULL;
15575 }
15576
15577 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t c);
15578
15579 9 static ListData warp_dlg_list(warptypelist, &font);
15580 9 static ListData warp_ret_list(warprlist, &font);
15581
15582 int32_t d_warpdestscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15583 {
15584 if(msg == MSG_START)
15585 {
15586 d->d1 = -1; //cached val
15587 d->d2 = -1; //cached dmap
15588 d->fg = 0; //cached 'force_16'
15589 }
15590 char* buf = (char*)d->dp;
15591 vector<DIALOG*>* dlgs = (vector<DIALOG*>*)d->dp2;
15592 int* dmap_ptr = (int*) d->dp3;
15593 if(!(buf && dmap_ptr))
15594 return D_O_K;
15595 bool is_overworld = ((DMaps[*dmap_ptr].type&dmfTYPE)==dmOVERW);
15596 int scrw = is_overworld ? 16 : 8, scrh = 9;
15597 const int max = 0x87;
15598 int bufval = zc_xtoi(buf);
15599 int val = vbound(bufval,0,max);
15600 auto& dm = DMaps[*dmap_ptr];
15601 auto val_offset = dm.xoff < 0 ? -dm.xoff : 0;
15602 bool force_16 = d->fg;
15603 if(!is_overworld)
15604 {
15605 if((val&0xF) >= 0x8)
15606 force_16 = true;
15607 else if((val&0xF) < val_offset && (val&0xF0) < 0x80)
15608 force_16 = true;
15609 }
15610 if(force_16) //can't bound, some quests need to warp out of bounds... -Em
15611 {
15612 scrw = 16; //just force show the larger grid instead
15613 val_offset = 0;
15614 }
15615
15616 int xscl = d->w/scrw;
15617 int yscl = d->h/scrh;
15618
15619 int ret = D_O_K;
15620 bool redraw = false;
15621 if(d->d1 != val)
15622 {
15623 redraw = true;
15624 d->d1 = val;
15625 }
15626 if(bufval != val)
15627 {
15628 redraw = true;
15629 sprintf(buf, "%X", val);
15630 }
15631 if(d->d2 != *dmap_ptr)
15632 {
15633 redraw = true;
15634 d->d2 = *dmap_ptr;
15635 }
15636 switch(msg)
15637 {
15638 case MSG_WANTFOCUS:
15639 ret = D_WANTFOCUS;
15640 break;
15641 case MSG_CLICK:
15642 {
15643 d->fg = force_16 ? 1 : 0;
15644 bool redraw2 = false;
15645 while(gui_mouse_b())
15646 {
15647 if(redraw2)
15648 {
15649 broadcast_dialog_message(MSG_DRAW, 0);
15650 redraw2 = false;
15651 }
15652 if(!d->fg && (gui_mouse_b()&2))
15653 {
15654 scrw = 16;
15655 xscl = d->w/scrw;
15656 yscl = d->h/scrh;
15657 val_offset = 0;
15658 d->fg = 1;
15659 redraw2 = true;
15660 }
15661 custom_vsync();
15662 if(!mouse_in_rect(d->x,d->y,d->w,d->h))
15663 continue;
15664 int mx = gui_mouse_x()-d->x, my = gui_mouse_y()-d->y;
15665 int y = vbound(my/yscl,0,scrh-1);
15666 auto offs = y==8 ? 0 : val_offset;
15667 int x = vbound(mx/xscl,offs,scrw-1);
15668 auto val2 = (y*16)+x;
15669 if(val2 > max) //out of bounds in the bottom-right
15670 continue;
15671 val = val2;
15672 if(d->d1 != val)
15673 {
15674 d->d1 = val;
15675 sprintf(buf, "%02X", val);
15676 redraw2 = true;
15677 }
15678 }
15679 redraw = true;
15680 d->fg = 0;
15681 break;
15682 }
15683 case MSG_DRAW:
15684 {
15685 rectfill(screen,d->x,d->y,d->x+d->w-1,d->y+d->h-1,jwin_pal[jcBOX]);
15686 jwin_draw_frame(screen, d->x-2, d->y-2, d->w+4, d->h+4, FR_MENU);
15687 for(int yind = 0; yind < scrh; ++yind)
15688 {
15689 auto gr = (yind < 8 ? dm.grid[yind] : 0);
15690 for(int xind = (yind == 8 ? 0 : val_offset); xind < scrw; ++xind)
15691 {
15692 int scr = xind+(yind*16);
15693 if(scr > max)
15694 continue;
15695 int fr = FR_MENU;
15696 if(scr == d->d1)
15697 fr = FR_GREEN;
15698 else if(!is_overworld && xind < 8 && (gr&(1<<(8-xind-1))))
15699 fr = FR_MENU_INV;
15700 jwin_draw_frame(screen, d->x+(xind*xscl), d->y+(yind*yscl), xscl, yscl, fr);
15701 }
15702 }
15703 break;
15704 }
15705 case MSG_XCHAR:
15706 {
15707 bool on_80 = (val&0xF0) == 0x80;
15708 switch(c>>8)
15709 {
15710 case KEY_UP:
15711 if((val&0xF0) && !(val_offset && on_80 && (val&0xF) < val_offset))
15712 {
15713 val -= 0x10;
15714 redraw = true;
15715 }
15716 ret |= D_USED_CHAR;
15717 break;
15718 case KEY_DOWN:
15719 if((val&0xF0) < ((val&0xF) < 0x8 ? 0x80 : 0x70))
15720 {
15721 val += 0x10;
15722 redraw = true;
15723 }
15724 ret |= D_USED_CHAR;
15725 break;
15726 case KEY_LEFT:
15727 if((val&0xF) > (on_80 ? 0 : val_offset))
15728 {
15729 --val;
15730 redraw = true;
15731 }
15732 ret |= D_USED_CHAR;
15733 break;
15734 case KEY_RIGHT:
15735 if((val&0xF) < scrw-1 && val < 0x87)
15736 {
15737 ++val;
15738 redraw = true;
15739 }
15740 ret |= D_USED_CHAR;
15741 break;
15742 }
15743 if(redraw)
15744 sprintf(buf, "%02X", val);
15745 break;
15746 }
15747 }
15748 if(redraw)
15749 {
15750 if(msg == MSG_IDLE)
15751 broadcast_dialog_message(MSG_DRAW,0);
15752 else
15753 {
15754 d->d1 = d->d2 = -1;
15755 object_message(d,MSG_IDLE,0);
15756 }
15757 }
15758
15759 return ret;
15760 }
15761
15762 int32_t tilewarpdmapxy[6] = {170,38,170,18,170,27};
15763 static DIALOG tilewarp_dlg[] =
15764 {
15765 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15766 9 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15767 9 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15768 9 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15769 9 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15770 9 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15771 //5
15772 9 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15773 9 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15774 9 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15775 9 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15776 9 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15777 //10
15778 9 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15779 9 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15780 9 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15781 9 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15782 9 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15783 //15
15784 9 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15785 9 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15786 9 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15787 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15788 };
15789
15790 int32_t sidewarpdmapxy[6] = {170,38,170,18,170,27};
15791 static DIALOG sidewarp_dlg[] =
15792 {
15793 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15794 9 { jwin_win_proc, 0, 0, 302, 178, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15795 9 { jwin_rtext_proc, 89, 43, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Type:", NULL, NULL },
15796 9 { jwin_rtext_proc, 57, 62, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15797 9 { jwin_rtext_proc, 57, 80, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15798 9 { jwin_droplist_proc, 91, 38, 193, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_dlg_list, NULL, NULL },
15799 //5
15800 9 { d_dropdmaplist_proc, 59, 57, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, tilewarpdmapxy },
15801 9 { jwin_hexedit_proc, 59, 76, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15802 9 { jwin_button_proc, 61, 152, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15803 9 { jwin_button_proc, 121, 152, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15804 9 { jwin_button_proc, 181, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15805 //10
15806 9 { jwin_rtext_proc, 82, 95, 100, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Use Warp Return:", NULL, NULL },
15807 9 { jwin_droplist_proc, 10, 105, 72, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &warp_ret_list, NULL, NULL },
15808 9 { jwin_check_proc, 10, 125, 129, 9, vc(14), vc(1), 0, 0, 1, 0, (void *) "Combos Carry Over", NULL, NULL },
15809 9 { d_warpdestscrsel_proc, 90, 76, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15810 9 { jwin_button_proc, 59, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "A", NULL, NULL },
15811 //15
15812 9 { jwin_button_proc, 109, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "B", NULL, NULL },
15813 9 { jwin_button_proc, 159, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "C", NULL, NULL },
15814 9 { jwin_button_proc, 209, 21, 50, 14, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "D", NULL, NULL },
15815 // 18
15816 9 { d_wflag_proc, 18, 17, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15817 9 { d_wflag_proc, 18, 47, 15, 8, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15818 // 20
15819 9 { d_wflag_proc, 8, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15820 9 { d_wflag_proc, 37, 27, 8, 15, vc(4), vc(0), 0, 0, 1, 0, NULL, NULL, NULL },
15821
15822 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15823 };
15824
15825 int32_t warpringxy[6] = {170,38,170,18,170,27};
15826 static DIALOG warpring_warp_dlg[] =
15827 {
15828 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
15829 9 { jwin_win_proc, 0, 0, 302, 145, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
15830 9 { jwin_rtext_proc, 57, 25, 40, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "DMap:", NULL, NULL },
15831 9 { jwin_rtext_proc, 57, 46, 64, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Screen: 0x", NULL, NULL },
15832 9 { d_dropdmaplist_proc, 59, 19, 225, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &dmap_list, NULL, warpringxy },
15833 9 { jwin_hexedit_proc, 59, 39, 24, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
15834 // 5
15835 9 { jwin_button_proc, 61, 115, 41, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
15836 9 { jwin_button_proc, 121, 115, 41, 21, vc(14), vc(1), 'g', D_EXIT, 0, 0, (void *) "&Go", NULL, NULL },
15837 9 { jwin_button_proc, 181, 115, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
15838 9 { d_warpdestscrsel_proc, 90, 39, 8*16, 8*9, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
15839
15840 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
15841 };
15842
15843 // Side warp flag procedure
15844 int32_t d_wflag_proc(int32_t msg,DIALOG *d,int32_t)
15845 {
15846 int32_t ret = D_O_K;
15847 switch(msg)
15848 {
15849 case MSG_DRAW:
15850 {
15851 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15852
15853 if(d->d1==1)
15854 {
15855 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15856 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15857
15858 if(d->flags&D_SELECTED)
15859 {
15860 int32_t e=d->d2&3;
15861
15862 if(d->w>d->h)
15863 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15864 else
15865 textprintf_centre_ex(screen,get_zc_font(font_lfont_l), d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15866 }
15867
15868 }
15869 else
15870 {
15871 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15872 }
15873 }
15874 break;
15875
15876 case MSG_CLICK:
15877 {
15878 if(d->flags & D_DISABLED)
15879 return D_O_K;
15880 bool rclick = gui_mouse_b() & 2;
15881 if(d->d1==1)
15882 {
15883 if(!(d->flags&D_SELECTED))
15884 {
15885 d->flags |= D_SELECTED;
15886 d->d2 &= 0x80;
15887 if (rclick)
15888 d->d2 |= 3;
15889 }
15890 else
15891 {
15892 if((d->d2&3) == (rclick?0:3))
15893 {
15894 d->flags ^= D_SELECTED;
15895 d->d2 &= 0x80;
15896 }
15897 else
15898 {
15899 int32_t f = d->d2&3;
15900 d->d2 &= 0x80;
15901 f += rclick ? -1 : 1;
15902 d->d2 |= f;
15903 }
15904 }
15905 }
15906 else
15907 {
15908 d->flags^=D_SELECTED;
15909 }
15910
15911 int32_t c2=(d->flags&D_SELECTED)?d->fg:d->bg;
15912
15913 if(d->d1==1)
15914 {
15915 jwin_draw_frame(screen,d->x,d->y,d->w,d->h, FR_DEEP);
15916 rectfill(screen,d->x+2, d->y+2, d->x+d->w-3, d->y+d->h-3,c2);
15917
15918 if(d->flags&D_SELECTED)
15919 {
15920 int32_t e=d->d2&3;
15921
15922 if(d->w>d->h)
15923 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15924 else
15925 textprintf_centre_ex(screen,get_zc_font(font_lfont_l),d->x+(d->w/2),d->y+(d->h/2)-4,jwin_pal[jcBOXFG],-1,"%c",e+0x41);
15926 }
15927 }
15928 else
15929 {
15930 rectfill(screen,d->x, d->y, d->x+d->w-1, d->y+d->h-1,c2);
15931 }
15932
15933
15934 while(gui_mouse_b())
15935 {
15936 /* do nothing */
15937 rest(1);
15938 }
15939 ret = D_REDRAWME;
15940 }
15941 break;
15942 }
15943
15944 return ret;
15945 }
15946
15947 int32_t d_dmapscrsel_proc(int32_t msg,DIALOG *d,int32_t c)
15948 {
15949 //these are here to bypass compiler warnings about unused arguments
15950 c=c;
15951
15952 int32_t ret = D_O_K;
15953
15954 switch(msg)
15955 {
15956 case MSG_CLICK:
15957 sprintf((char*)((d+2)->dp),"%X%X",vbound((gui_mouse_y()-d->y)/4,0,7),vbound((gui_mouse_x()-d->x)/(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?4:8),0,(((DMaps[(d-1)->d1].type&dmfTYPE)==1)?15:7)));
15958 object_message(d+2, MSG_DRAW, 0);
15959 break;
15960 }
15961
15962 return ret;
15963 }
15964
15965 int32_t warpdestsel_x=-1;
15966 int32_t warpdestsel_y=-1;
15967 int32_t warpdestmap=-1;
15968 int32_t warpdestscr=-1;
15969
15970 int32_t jwin_minibutton_proc(int32_t msg,DIALOG *d,int32_t c)
15971 {
15972 switch(msg)
15973 {
15974 case MSG_DRAW:
15975 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, false);
15976 return D_O_K;
15977 break;
15978 }
15979
15980 return jwin_button_proc(msg,d,c);
15981 }
15982
15983 int32_t d_triggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
15984 {
15985 static BITMAP *dummy=create_bitmap_ex(8, 1, 1);
15986
15987 switch(msg)
15988 {
15989 case MSG_START:
15990 d->w=gui_textout_ln(dummy, font, (uint8_t *)d->dp, 0, 0, jwin_pal[jcMEDDARK], -1, 0)+4;
15991 d->h=text_height(font)+5;
15992 break;
15993
15994 case MSG_GOTFOCUS:
15995 d->flags&=~D_GOTFOCUS;
15996 break;
15997
15998 }
15999
16000 return jwin_minibutton_proc(msg,d,c);
16001 }
16002
16003 int32_t d_alltriggerbutton_proc(int32_t msg,DIALOG *d,int32_t c)
16004 {
16005 DIALOG *temp_d;
16006 int32_t ret=d_triggerbutton_proc(msg,d,c);
16007
16008 switch(msg)
16009 {
16010 case MSG_CLICK:
16011 temp_d=d-1;
16012
16013 while(temp_d->proc==d_triggerbutton_proc)
16014 {
16015 temp_d->flags&=~D_SELECTED;
16016 temp_d->flags|=D_DIRTY;
16017
16018 if(d->flags&D_SELECTED)
16019 {
16020 temp_d->flags|=D_SELECTED;
16021 }
16022
16023 --temp_d;
16024 }
16025
16026 break;
16027 }
16028
16029 return ret;
16030 }
16031
16032 int32_t d_ticsedit_proc(int32_t msg,DIALOG *d,int32_t c)
16033 {
16034 int32_t ret = jwin_edit_proc(msg,d,c);
16035
16036 if(msg==MSG_DRAW)
16037 {
16038 int32_t tics=vbound(atoi((char*)d->dp),0,65535);
16039 sprintf((char*)(d+1)->dp,"%s %s",ticksstr(tics),tics==0?"(No Timed Warp)":" ");
16040 object_message(d+1,MSG_DRAW,c);
16041 }
16042
16043 return ret;
16044 }
16045
16046 9 static ListData warp_effect_list(warpeffectlist,&font);
16047
16048 struct tw_data
16049 {
16050 int twscr[4], twtype[4], twdmap[4], wret[4];
16051 byte oflags;
16052 optional<uint> loaded;
16053
16054 tw_data(mapscr* scr) {load_scr(scr);}
16055 void load_scr(mapscr* scr)
16056 {
16057 oflags = scr->tilewarpoverlayflags;
16058 for(int q = 0; q < 4; ++q)
16059 {
16060 twscr[q] = scr->tilewarpscr[q];
16061 twtype[q] = scr->tilewarptype[q];
16062 twdmap[q] = scr->tilewarpdmap[q];
16063 wret[q] = (scr->warpreturnc >> (2*q))&3;
16064 }
16065 loaded.reset();
16066 }
16067 void save_scr(mapscr* scr)
16068 {
16069 saved=false;
16070 scr->tilewarpoverlayflags = oflags;
16071 scr->warpreturnc = scr->warpreturnc & 0xFF00;
16072 for(int q = 0; q < 4; ++q)
16073 {
16074 scr->tilewarpscr[q] = twscr[q];
16075 scr->tilewarptype[q] = twtype[q];
16076 scr->tilewarpdmap[q] = twdmap[q];
16077 scr->warpreturnc |= wret[q] << (2*q);
16078 }
16079 }
16080
16081 void load(uint ind)
16082 {
16083 if(ind >= 4) return;
16084 loaded = ind;
16085 tilewarp_dlg[4].d1 = twtype[ind];
16086 tilewarp_dlg[5].d1 = twdmap[ind];
16087 char* buf = (char*)tilewarp_dlg[6].dp;
16088 sprintf(buf,"%02X",twscr[ind]);
16089 tilewarp_dlg[11].d1 = wret[ind];
16090 SETFLAG(tilewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
16091 for(int q = 0; q < 4; ++q)
16092 SETFLAG(tilewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
16093 }
16094 void save(uint ind)
16095 {
16096 if(ind >= 4) return;
16097 twtype[ind] = tilewarp_dlg[4].d1;
16098 twdmap[ind] = tilewarp_dlg[5].d1;
16099 char* buf = (char*)tilewarp_dlg[6].dp;
16100 twscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16101 wret[ind] = tilewarp_dlg[11].d1;
16102 set_bit(&oflags, ind, tilewarp_dlg[12].flags & D_SELECTED);
16103 }
16104 void save()
16105 {
16106 if(loaded)
16107 save(*loaded);
16108 }
16109 void swap(uint ind)
16110 {
16111 if(ind >= 4) return;
16112 if(loaded)
16113 {
16114 save(*loaded);
16115 if(*loaded == ind)
16116 return;
16117 }
16118 load(ind);
16119 }
16120 };
16121 int32_t onTileWarp()
16122 {
16123 restore_mouse();
16124 tilewarp_dlg[0].dp=(void *) "Tile Warp";
16125 tilewarp_dlg[0].dp2=get_zc_font(font_lfont);
16126
16127 mapscr* mptr = Map.CurrScr();
16128 char buf[10];
16129 tilewarp_dlg[6].dp=buf;
16130 tilewarp_dlg[13].dp = buf;
16131 tilewarp_dlg[13].dp3 = &tilewarp_dlg[5].d1;
16132
16133 vector<DIALOG*> dlgs;
16134 dlgs.push_back(&tilewarp_dlg[5]);
16135 dlgs.push_back(&tilewarp_dlg[6]);
16136 tilewarp_dlg[13].dp2 = &dlgs;
16137
16138 tw_data data(mptr);
16139 data.load(0);
16140
16141 dmap_list_size=MAXDMAPS;
16142 dmap_list_zero=true;
16143
16144 large_dialog(tilewarp_dlg);
16145
16146 bool running = true;
16147 int ret;
16148 do
16149 {
16150 ret = do_zqdialog(tilewarp_dlg,-1);
16151 switch(ret)
16152 {
16153 // OK, GO
16154 case 7: case 8:
16155 running = false;
16156 data.save();
16157 data.save_scr(mptr);
16158 refresh(rMENU);
16159 break;
16160 //Cancel
16161 case 9:
16162 running = false;
16163 break;
16164 //A,B,C,D
16165 case 14: case 15: case 16: case 17:
16166 data.swap(ret-14);
16167 break;
16168 }
16169 }
16170 while(running);
16171
16172 if(ret==8) //GO
16173 {
16174 int32_t index = *data.loaded;
16175
16176 FlashWarpSquare = -1;
16177 int32_t tm = Map.getCurrMap();
16178 int32_t ts = Map.getCurrScr();
16179 int32_t thistype = mptr->tilewarptype[index];
16180 Map.dowarp(0,index);
16181
16182 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtCAVE && thistype != wtSCROLL)
16183 {
16184 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(index*2))&3;
16185 FlashWarpClk = 32;
16186 }
16187
16188 refresh(rALL);
16189 }
16190
16191 return D_O_K;
16192 }
16193
16194 struct sw_data
16195 {
16196 int swscr[4], swtype[4], swdmap[4], wret[4];
16197 byte oflags;
16198 optional<uint> loaded;
16199
16200 sw_data(mapscr* scr) {load_scr(scr);}
16201 void load_scr(mapscr* scr)
16202 {
16203 oflags = scr->sidewarpoverlayflags;
16204 for(int q = 0; q < 4; ++q)
16205 {
16206 swscr[q] = scr->sidewarpscr[q];
16207 swtype[q] = scr->sidewarptype[q];
16208 swdmap[q] = scr->sidewarpdmap[q];
16209 wret[q] = (scr->warpreturnc >> (2*(q+4)))&3;
16210 }
16211 loaded.reset();
16212
16213 for(int32_t i=0; i<4; i++)
16214 {
16215 sidewarp_dlg[18+i].d2 = 0x80;
16216 if(scr->flags2&(1<<i))
16217 {
16218 sidewarp_dlg[18+i].flags = D_SELECTED ;
16219 sidewarp_dlg[18+i].d2 |= (scr->sidewarpindex>>(2*i))&3;
16220 }
16221 else
16222 {
16223 sidewarp_dlg[18+i].flags = 0;
16224 }
16225 }
16226 }
16227 void save_scr(mapscr* scr)
16228 {
16229 saved=false;
16230 scr->sidewarpoverlayflags = oflags;
16231 scr->warpreturnc = scr->warpreturnc & 0x00FF;
16232 for(int q = 0; q < 4; ++q)
16233 {
16234 scr->sidewarpscr[q] = swscr[q];
16235 scr->sidewarptype[q] = swtype[q];
16236 scr->sidewarpdmap[q] = swdmap[q];
16237 scr->warpreturnc |= wret[q] << (2*(q+4));
16238 }
16239
16240 scr->flags2 &= ~0xF;
16241 scr->sidewarpindex = 0;
16242 for(int32_t i=0; i<4; i++)
16243 {
16244 if(sidewarp_dlg[18+i].flags & D_SELECTED)
16245 scr->flags2 |= 1<<i;
16246 scr->sidewarpindex |= (sidewarp_dlg[18+i].d2&3) << (i*2);
16247 }
16248 }
16249
16250 void load(uint ind)
16251 {
16252 if(ind >= 4) return;
16253 loaded = ind;
16254 sidewarp_dlg[4].d1 = swtype[ind];
16255 sidewarp_dlg[5].d1 = swdmap[ind];
16256 char* buf = (char*)sidewarp_dlg[6].dp;
16257 sprintf(buf,"%02X",swscr[ind]);
16258 sidewarp_dlg[11].d1 = wret[ind];
16259 SETFLAG(sidewarp_dlg[12].flags, D_SELECTED, get_bit(&oflags,ind));
16260 for(int q = 0; q < 4; ++q)
16261 SETFLAG(sidewarp_dlg[14+q].flags,(D_SELECTED|D_DISABLED),q==ind);
16262 }
16263 void save(uint ind)
16264 {
16265 if(ind >= 4) return;
16266 swtype[ind] = sidewarp_dlg[4].d1;
16267 swdmap[ind] = sidewarp_dlg[5].d1;
16268 char* buf = (char*)sidewarp_dlg[6].dp;
16269 swscr[ind] = vbound(zc_xtoi(buf),0x00,0x87);
16270 wret[ind] = sidewarp_dlg[11].d1;
16271 set_bit(&oflags, ind, sidewarp_dlg[12].flags & D_SELECTED);
16272 }
16273 void save()
16274 {
16275 if(loaded)
16276 save(*loaded);
16277 }
16278 void swap(uint ind)
16279 {
16280 if(ind >= 4) return;
16281 if(loaded)
16282 {
16283 save(*loaded);
16284 if(*loaded == ind)
16285 return;
16286 }
16287 load(ind);
16288 }
16289 };
16290 int32_t onSideWarp()
16291 {
16292 restore_mouse();
16293 sidewarp_dlg[0].dp=(void *) "Side Warp";
16294 sidewarp_dlg[0].dp2=get_zc_font(font_lfont);
16295
16296 mapscr* mptr = Map.CurrScr();
16297 char buf[10];
16298 sidewarp_dlg[6].dp=buf;
16299 sidewarp_dlg[13].dp = buf;
16300 sidewarp_dlg[13].dp3 = &sidewarp_dlg[5].d1;
16301
16302 vector<DIALOG*> dlgs;
16303 dlgs.push_back(&sidewarp_dlg[5]);
16304 dlgs.push_back(&sidewarp_dlg[6]);
16305 sidewarp_dlg[13].dp2 = &dlgs;
16306
16307 sw_data data(mptr);
16308 data.load(0);
16309
16310 dmap_list_size=MAXDMAPS;
16311 dmap_list_zero=true;
16312
16313 large_dialog(sidewarp_dlg);
16314
16315 bool running = true;
16316 int ret;
16317 do
16318 {
16319 ret = do_zqdialog(sidewarp_dlg,-1);
16320 switch(ret)
16321 {
16322 // OK, GO
16323 case 7: case 8:
16324 running = false;
16325 data.save();
16326 data.save_scr(mptr);
16327 refresh(rMENU);
16328 break;
16329 //Cancel
16330 case 9:
16331 running = false;
16332 break;
16333 //A,B,C,D
16334 case 14: case 15: case 16: case 17:
16335 data.swap(ret-14);
16336 break;
16337 }
16338 }
16339 while(running);
16340
16341 if(ret==8) //GO
16342 {
16343 int32_t index = *data.loaded;
16344
16345 FlashWarpSquare = -1;
16346 int32_t tm = Map.getCurrMap();
16347 int32_t ts = Map.getCurrScr();
16348
16349 int32_t thistype = mptr->sidewarptype[index];
16350 Map.dowarp(1,index);
16351
16352 if((ts!=Map.getCurrScr() || tm!=Map.getCurrMap()) && thistype != wtSCROLL)
16353 {
16354 FlashWarpSquare = (TheMaps[tm*MAPSCRS+ts].warpreturnc>>(8+index*2))&3;
16355 FlashWarpClk = 0x20;
16356 }
16357
16358 refresh(rALL);
16359 }
16360
16361 return D_O_K;
16362 }
16363
16364
16365
16366 const char *dirlist(int32_t index, int32_t *list_size)
16367 {
16368 if(index>=0)
16369 {
16370 if(index>3)
16371 index=3;
16372
16373 return mazedirstr[index];
16374 }
16375
16376 *list_size=4;
16377 return NULL;
16378 }
16379
16380 9 static ListData path_dlg_list(dirlist, &font);
16381
16382 static DIALOG path_dlg[] =
16383 {
16384 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
16385 9 { jwin_win_proc, 80, 57, 161, 164, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Maze Path", NULL, NULL },
16386 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16387 9 { jwin_text_proc, 94, 106, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16388 9 { jwin_text_proc, 94, 124, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16389 9 { jwin_text_proc, 94, 142, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16390 9 { jwin_text_proc, 94, 160, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "4th", NULL, NULL },
16391 9 { jwin_text_proc, 94, 178, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Exit", NULL, NULL },
16392 9 { jwin_droplist_proc, 140, 102, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16393 9 { jwin_droplist_proc, 140, 120, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16394 9 { jwin_droplist_proc, 140, 138, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16395 9 { jwin_droplist_proc, 140, 156, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16396 9 { jwin_droplist_proc, 140, 174, 80+1, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &path_dlg_list, NULL, NULL },
16397 9 { jwin_button_proc, 90, 194, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16398 9 { jwin_button_proc, 170, 194, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16399 9 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
16400 9 { jwin_text_proc, 87, 82, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "A Lost Woods-style maze screen", NULL, NULL },
16401 9 { jwin_text_proc, 87, 92, 192, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "with a normal and secret exit.", NULL, NULL },
16402 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16403 };
16404
16405 int32_t onPath()
16406 {
16407 restore_mouse();
16408 path_dlg[0].dp2=get_zc_font(font_lfont);
16409
16410 for(int32_t i=0; i<4; i++)
16411 path_dlg[i+7].d1 = Map.CurrScr()->path[i];
16412
16413 path_dlg[11].d1 = Map.CurrScr()->exitdir;
16414
16415 large_dialog(path_dlg);
16416
16417 int32_t ret;
16418
16419 do
16420 {
16421 ret=do_zqdialog(path_dlg,7);
16422
16423 if(ret==12) for(int32_t i=0; i<4; i++)
16424 {
16425 if(path_dlg[i+7].d1 == path_dlg[11].d1)
16426 {
16427 if(jwin_alert("Exit Problem","One of the path's directions is","also the normal Exit direction! Continue?",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==2)
16428 ret = -1;
16429
16430 break;
16431 }
16432 }
16433 }
16434 while(ret == -1);
16435
16436 if(ret==12)
16437 {
16438 saved=false;
16439
16440 for(int32_t i=0; i<4; i++)
16441 Map.CurrScr()->path[i] = path_dlg[i+7].d1;
16442
16443 Map.CurrScr()->exitdir = path_dlg[11].d1;
16444
16445 if(!(Map.CurrScr()->flags&fMAZE))
16446 if(jwin_alert("Screen Flag","Turn on the 'Use Maze Path' Screen Flag?","(Go to 'Screen Data' to turn it off.)",NULL,"Yes","No",'y','n',get_zc_font(font_lfont))==1)
16447 Map.CurrScr()->flags |= fMAZE;
16448 }
16449
16450 refresh(rMAP+rMENU);
16451 return D_O_K;
16452 }
16453
16454
16455
16456 static DIALOG editinfo_dlg[] =
16457 {
16458 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16459 9 { jwin_win_proc, 0, 10, 208, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16460 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16461 9 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16462 9 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16463 9 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16464 9 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16465 9 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16466 9 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16467 // 8
16468 9 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16469 9 { d_ndroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16470 9 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16471 9 { d_ndroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16472 9 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16473 9 { d_ndroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16474 9 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16475 9 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16476 // 16
16477 9 { jwin_button_proc, 34, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16478 9 { jwin_button_proc, 114, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16479 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16480 };
16481
16482 void EditInfoType(int32_t index)
16483 {
16484 char ps1[6],ps2[6],ps3[6];
16485 char infoname[33];
16486 char caption[40];
16487
16488 int32_t str1, str2, str3;
16489
16490 sprintf(caption,"Info Data %d",index);
16491 editinfo_dlg[0].dp = caption;
16492 editinfo_dlg[0].dp2 = get_zc_font(font_lfont);
16493
16494 sprintf(ps1,"%d",QMisc.info[index].price[0]);
16495 sprintf(ps2,"%d",QMisc.info[index].price[1]);
16496 sprintf(ps3,"%d",QMisc.info[index].price[2]);
16497 strncpy(infoname,QMisc.info[index].name,32);
16498 infoname[32] = 0;
16499 editinfo_dlg[8].dp = ps1;
16500 editinfo_dlg[10].dp = ps2;
16501 editinfo_dlg[12].dp = ps3;
16502 editinfo_dlg[15].dp = infoname;
16503 str1 = QMisc.info[index].str[0];
16504 str2 = QMisc.info[index].str[1];
16505 str3 = QMisc.info[index].str[2];
16506 editinfo_dlg[9].d1 = MsgStrings[str1].listpos;
16507 editinfo_dlg[11].d1 = MsgStrings[str2].listpos;
16508 editinfo_dlg[13].d1 = MsgStrings[str3].listpos;
16509 ListData msgs_list(msgslist2, &a4fonts[font_lfont_l]);
16510 editinfo_dlg[9].dp =
16511 editinfo_dlg[11].dp =
16512 editinfo_dlg[13].dp = (void *) &msgs_list;
16513
16514 large_dialog(editinfo_dlg);
16515
16516 int32_t ret = do_zqdialog(editinfo_dlg,-1);
16517
16518 if(ret==16)
16519 {
16520 saved=false;
16521 QMisc.info[index].price[0] = vbound(atoi(ps1), 0, 65535);
16522 QMisc.info[index].price[1] = vbound(atoi(ps2), 0, 65535);
16523 QMisc.info[index].price[2] = vbound(atoi(ps3), 0, 65535);
16524 strncpy(QMisc.info[index].name,infoname,32);
16525 str1 = editinfo_dlg[9].d1;
16526 str2 = editinfo_dlg[11].d1;
16527 str3 = editinfo_dlg[13].d1;
16528 QMisc.info[index].str[0] = msg_at_pos(str1);
16529 QMisc.info[index].str[1] = msg_at_pos(str2);
16530 QMisc.info[index].str[2] = msg_at_pos(str3);
16531
16532 //move 0s to the end
16533 word swaptmp;
16534
16535 if(QMisc.info[index].str[0] == 0)
16536 {
16537 //possibly permute the infos
16538 if(QMisc.info[index].str[1] != 0)
16539 {
16540 //swap
16541 swaptmp = QMisc.info[index].str[0];
16542 QMisc.info[index].str[0] = QMisc.info[index].str[1];
16543 QMisc.info[index].str[1] = swaptmp;
16544 swaptmp = QMisc.info[index].price[0];
16545 QMisc.info[index].price[0] = QMisc.info[index].price[1];
16546 QMisc.info[index].price[1] = swaptmp;
16547 }
16548 else if(QMisc.info[index].str[2] != 0)
16549 {
16550 //move info 0 to 1, 1 to 2, and 2 to 0
16551 swaptmp = QMisc.info[index].str[0];
16552 QMisc.info[index].str[0] = QMisc.info[index].str[2];
16553 QMisc.info[index].str[2] = QMisc.info[index].str[1];
16554 QMisc.info[index].str[1] = swaptmp;
16555 swaptmp = QMisc.info[index].price[0];
16556 QMisc.info[index].price[0] = QMisc.info[index].price[2];
16557 QMisc.info[index].price[2] = QMisc.info[index].price[1];
16558 QMisc.info[index].price[1] = swaptmp;
16559 }
16560 }
16561
16562 if(QMisc.info[index].str[1] == 0 && QMisc.info[index].str[2] != 0)
16563 //swap
16564 {
16565 swaptmp = QMisc.info[index].str[1];
16566 QMisc.info[index].str[1] = QMisc.info[index].str[2];
16567 QMisc.info[index].str[2] = swaptmp;
16568 swaptmp = QMisc.info[index].price[1];
16569 QMisc.info[index].price[1] = QMisc.info[index].price[2];
16570 QMisc.info[index].price[2] = swaptmp;
16571 }
16572 }
16573 }
16574
16575 int32_t onInfoTypes()
16576 {
16577 info_list_size = 256;
16578
16579 int32_t index = select_data("Info Types",0,infolist,"Edit","Done",get_zc_font(font_lfont));
16580
16581 while(index!=-1)
16582 {
16583 EditInfoType(index);
16584
16585 index = select_data("Info Types",index,infolist,"Edit","Done",get_zc_font(font_lfont));
16586 }
16587
16588 return D_O_K;
16589 }
16590
16591
16592
16593 //This dialogie is self-contained, and does not use dialogue control numbers in a separate array to generate its fields.
16594 static DIALOG editshop_dlg[] =
16595 {
16596 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16597 9 { jwin_win_proc, 0, 10, 221, 204, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16598 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16599 9 { jwin_text_proc, 24, 60, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "1st", NULL, NULL },
16600 9 { jwin_text_proc, 24, 106, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "2nd", NULL, NULL },
16601 9 { jwin_text_proc, 24, 152, 48, 8, vc(7), vc(1), 0, 0, 0, 0, (void *) "3rd", NULL, NULL },
16602 9 { jwin_text_proc, 56, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16603 9 { jwin_text_proc, 56, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16604 9 { jwin_text_proc, 56, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Price:", NULL, NULL },
16605 // 8
16606 9 { jwin_edit_proc, 86, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16607 9 { d_nidroplist_proc, 56, 74, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16608 9 { jwin_edit_proc, 86, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16609 9 { d_nidroplist_proc, 56, 120, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16610 9 { jwin_edit_proc, 86, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16611 9 { d_nidroplist_proc, 56, 166, 137, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16612 9 { jwin_text_proc, 24, 42, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16613 9 { jwin_edit_proc, 56, 38, 137, 16, vc(12), vc(1), 0, 0, 31, 0, NULL, NULL, NULL },
16614
16615 // 16
16616 9 { jwin_button_proc, 40, 188, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16617 9 { jwin_button_proc, 121, 188, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16618 //18
16619 9 { jwin_text_proc, 130, 60, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16620 9 { jwin_text_proc, 130, 106, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16621 9 { jwin_text_proc, 130, 152, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Info:", NULL, NULL },
16622 // 21
16623 9 { jwin_edit_proc, 155, 56, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16624 9 { jwin_edit_proc, 155, 102, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16625 9 { jwin_edit_proc, 155, 148, 32, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16626
16627 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16628 };
16629
16630 void EditShopType(int32_t index)
16631 {
16632
16633 build_bii_list(true);
16634 char ps1[6],ps2[6],ps3[6];
16635 char info1[6],info2[6],info3[6];
16636 char shopname[32];
16637 char caption[40];
16638
16639 sprintf(caption,"Shop Data %d",index);
16640 editshop_dlg[0].dp = caption;
16641 editshop_dlg[0].dp2=get_zc_font(font_lfont);
16642
16643 sprintf(ps1,"%d",QMisc.shop[index].price[0]);
16644 sprintf(ps2,"%d",QMisc.shop[index].price[1]);
16645 sprintf(ps3,"%d",QMisc.shop[index].price[2]);
16646
16647 sprintf(info1,"%d",QMisc.shop[index].str[0]);
16648 sprintf(info2,"%d",QMisc.shop[index].str[1]);
16649 sprintf(info3,"%d",QMisc.shop[index].str[2]);
16650
16651 sprintf(shopname,"%s",QMisc.shop[index].name);
16652 editshop_dlg[8].dp = ps1;
16653 editshop_dlg[10].dp = ps2;
16654 editshop_dlg[12].dp = ps3;
16655 editshop_dlg[15].dp = shopname;
16656
16657 editshop_dlg[21].dp = info1;
16658 editshop_dlg[22].dp = info2;
16659 editshop_dlg[23].dp = info3;
16660
16661 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16662
16663 editshop_dlg[9].dp = (void *) &item_list;
16664 editshop_dlg[11].dp = (void *) &item_list;
16665 editshop_dlg[13].dp = (void *) &item_list;
16666
16667 for(int32_t i=0; i<3; ++i)
16668 {
16669 if(QMisc.shop[index].hasitem[i])
16670 {
16671 for(int32_t j=0; j<bii_cnt; j++)
16672 {
16673 if(bii[j].i == QMisc.shop[index].item[i])
16674 {
16675 editshop_dlg[9+(i<<1)].d1 = j;
16676 }
16677 }
16678 }
16679 else
16680 {
16681 editshop_dlg[9+(i<<1)].d1 = -2;
16682 }
16683 }
16684
16685 large_dialog(editshop_dlg);
16686
16687 int32_t ret = do_zqdialog(editshop_dlg,-1);
16688
16689 if(ret==16)
16690 {
16691 saved=false;
16692 QMisc.shop[index].price[0] = vbound(atoi(ps1), 0, 65535);
16693 QMisc.shop[index].price[1] = vbound(atoi(ps2), 0, 65535);
16694 QMisc.shop[index].price[2] = vbound(atoi(ps3), 0, 65535);
16695
16696 QMisc.shop[index].str[0] = vbound(atoi(info1), 0, 65535);
16697 QMisc.shop[index].str[1] = vbound(atoi(info2), 0, 65535);
16698 QMisc.shop[index].str[2] = vbound(atoi(info3), 0, 65535);
16699
16700 snprintf(QMisc.shop[index].name, 32, "%s",shopname);
16701
16702 for(int32_t i=0; i<3; ++i)
16703 {
16704 if(bii[editshop_dlg[9+(i<<1)].d1].i == -2)
16705 {
16706 QMisc.shop[index].hasitem[i] = 0;
16707 QMisc.shop[index].item[i] = 0;
16708 QMisc.shop[index].price[i] = 0;
16709 }
16710 else
16711 {
16712 QMisc.shop[index].hasitem[i] = 1;
16713 QMisc.shop[index].item[i] = bii[editshop_dlg[9+(i<<1)].d1].i;
16714 }
16715 }
16716
16717 //filter all the 0 items to the end (yeah, bubble sort; sue me)
16718 word swaptmp;
16719
16720 for(int32_t j=0; j<3-1; j++)
16721 {
16722 for(int32_t k=0; k<2-j; k++)
16723 {
16724 if(QMisc.shop[index].hasitem[k]==0)
16725 {
16726 swaptmp = QMisc.shop[index].item[k];
16727 QMisc.shop[index].item[k] = QMisc.shop[index].item[k+1];
16728 QMisc.shop[index].item[k+1] = swaptmp;
16729 swaptmp = QMisc.shop[index].price[k];
16730 QMisc.shop[index].price[k] = QMisc.shop[index].price[k+1];
16731 QMisc.shop[index].price[k+1] = swaptmp;
16732 swaptmp = QMisc.shop[index].hasitem[k];
16733 QMisc.shop[index].hasitem[k] = QMisc.shop[index].item[k+1];
16734 QMisc.shop[index].hasitem[k+1] = swaptmp;
16735 }
16736 }
16737 }
16738 }
16739 }
16740
16741 int32_t onShopTypes()
16742 {
16743 shop_list_size = 256;
16744
16745 int32_t index = select_data("Shop Types",0,shoplist,"Edit","Done",get_zc_font(font_lfont));
16746
16747 while(index!=-1)
16748 {
16749 EditShopType(index);
16750 index = select_data("Shop Types",index,shoplist,"Edit","Done",get_zc_font(font_lfont));
16751 }
16752
16753 return D_O_K;
16754 }
16755
16756 void call_bottle_dlg(int32_t index);
16757 int32_t onBottleTypes()
16758 {
16759 bottle_list_size = 64;
16760 int32_t index = 0;
16761
16762 while(index > -1)
16763 {
16764 index = select_data("Bottle Types", index, bottlelist, "Edit", "Done", get_zc_font(font_lfont));
16765 if(index > -1)
16766 call_bottle_dlg(index);
16767 }
16768
16769 return D_O_K;
16770 }
16771
16772 void call_bottleshop_dlg(int32_t index);
16773 int32_t onBottleShopTypes()
16774 {
16775 bottleshop_list_size = 256;
16776 int32_t index = 0;
16777
16778 while(index > -1)
16779 {
16780 index = select_data("Bottle Shop Types", index, bottleshoplist, "Edit", "Done", get_zc_font(font_lfont));
16781 if(index > -1)
16782 call_bottleshop_dlg(index);
16783 }
16784
16785 return D_O_K;
16786 }
16787
16788
16789 static char item_drop_set_str_buf[70];
16790 int32_t item_drop_set_list_size=MAXITEMDROPSETS;
16791
16792 const char *itemdropsetlist(int32_t index, int32_t *list_size)
16793 {
16794 if(index>=0)
16795 {
16796 bound(index,0,item_drop_set_list_size-1);
16797 sprintf(item_drop_set_str_buf,"%3d: %s",index,item_drop_sets[index].name);
16798 return item_drop_set_str_buf;
16799 }
16800
16801 *list_size=item_drop_set_list_size;
16802 return NULL;
16803 }
16804
16805 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c);
16806
16807 static int32_t edititemdropset_1_list[] =
16808 {
16809 // dialog control number
16810 10, 11, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,24,25,26,27,28, -1
16811 };
16812
16813 static int32_t edititemdropset_2_list[] =
16814 {
16815 // dialog control number
16816 12, 13, 29, 30, 31, 32, 33,34,35,36,37,38,39,40,41,42,43, -1
16817 };
16818
16819 static TABPANEL edititemdropset_tabs[] =
16820 {
16821 // (text)
16822 { (char *)" Page 1 ", D_SELECTED, edititemdropset_1_list, 0, NULL },
16823 { (char *)" Page 2 ", 0, edititemdropset_2_list, 0, NULL },
16824 { NULL, 0, NULL, 0, NULL }
16825 };
16826
16827 static DIALOG edititemdropset_dlg[] =
16828 {
16829 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
16830 9 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
16831 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
16832
16833 // 2
16834 9 { jwin_button_proc, 89, 213, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
16835 9 { jwin_button_proc, 169, 213, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
16836
16837 // 4
16838 9 { jwin_text_proc, 9, 29, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Name:", NULL, NULL },
16839 9 { jwin_edit_proc, 39, 25, 275, 16, vc(12), vc(1), 0, 0, 32, 0, NULL, NULL, NULL },
16840 9 { jwin_text_proc, 9, 47, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Nothing Chance:", NULL, NULL },
16841 9 { d_itemdropedit_proc, 84, 43, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16842
16843 9 { jwin_tab_proc, 4, 65, 312, 143, vc(0), vc(15), 0, 0, 0, 0, (void *) edititemdropset_tabs, NULL, (void *)edititemdropset_dlg },
16844 9 { jwin_text_proc, 114, 43+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16845 // 10
16846 9 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16847 9 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16848 9 { jwin_text_proc, 10, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Chance:", NULL, NULL },
16849 9 { jwin_text_proc, 56, 87, 88, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Item:", NULL, NULL },
16850
16851 // 14
16852 9 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16853 9 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16854 9 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16855 9 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16856 9 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16857 9 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16858 9 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16859 9 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16860 9 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16861 9 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16862 9 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16863 9 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16864 9 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16865 9 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16866 9 { jwin_text_proc, 37, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16867 // 29
16868 9 { d_itemdropedit_proc, 9, 96, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16869 9 { d_idroplist_proc, 55, 96, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16870 9 { jwin_text_proc, 37, 96+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16871 9 { d_itemdropedit_proc, 9, 118, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16872 9 { d_idroplist_proc, 55, 118, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16873 9 { jwin_text_proc, 37, 118+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16874 9 { d_itemdropedit_proc, 9, 140, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16875 9 { d_idroplist_proc, 55, 140, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16876 9 { jwin_text_proc, 37, 140+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16877 9 { d_itemdropedit_proc, 9, 162, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16878 9 { d_idroplist_proc, 55, 162, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16879 9 { jwin_text_proc, 37, 162+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16880 9 { d_itemdropedit_proc, 9, 184, 26, 16, vc(12), vc(1), 0, 0, 5, 0, NULL, NULL, NULL },
16881 9 { d_idroplist_proc, 55, 184, 233, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
16882 9 { jwin_text_proc, 39, 184+4, 26, 16, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
16883 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
16884 };
16885
16886 int32_t d_itemdropedit_proc(int32_t msg,DIALOG *d,int32_t c)
16887 {
16888 int32_t ret = jwin_edit_proc(msg,d,c);
16889
16890 if(msg==MSG_DRAW)
16891 {
16892 int32_t t = atoi((char*)edititemdropset_dlg[7].dp);
16893
16894 for(int32_t i=0; i<10; ++i)
16895 {
16896 t += atoi((char*)edititemdropset_dlg[14+(i*3)].dp);
16897 }
16898
16899 {
16900 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[7].dp) / zc_max(t,1));
16901 sprintf((char*)edititemdropset_dlg[9].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16902 object_message(&edititemdropset_dlg[9],MSG_DRAW,c);
16903 }
16904
16905 for(int32_t i=0; i<10; ++i)
16906 {
16907 int32_t t2 = (int32_t)(100*atoi((char*)edititemdropset_dlg[14+(i*3)].dp) / zc_max(t,1));
16908 sprintf((char*)edititemdropset_dlg[16+(i*3)].dp,"%d%%%s",t2, t2 <= 11 ? " ":"");
16909 object_message(&edititemdropset_dlg[16+(i*3)],MSG_DRAW,c);
16910 }
16911
16912 }
16913
16914 return ret;
16915 }
16916
16917 void EditItemDropSet(int32_t index)
16918 {
16919 build_bii_list(true);
16920 char chance[11][10];
16921 char itemdropsetname[64];
16922 char caption[40];
16923 char percent_str[11][5];
16924
16925 sprintf(caption,"Item Drop Set Data %d",index);
16926 edititemdropset_dlg[0].dp = caption;
16927 edititemdropset_dlg[0].dp2=get_zc_font(font_lfont);
16928
16929 sprintf(itemdropsetname,"%s",item_drop_sets[index].name);
16930 edititemdropset_dlg[5].dp = itemdropsetname;
16931
16932 sprintf(chance[0],"%d",item_drop_sets[index].chance[0]);
16933 edititemdropset_dlg[7].dp = chance[0];
16934
16935 ListData item_list(itemlist_num, &a4fonts[font_lfont_l]);
16936 sprintf(percent_str[0]," ");
16937 edititemdropset_dlg[9].dp = percent_str[0];
16938
16939 for(int32_t i=0; i<10; ++i)
16940 {
16941 sprintf(chance[i+1],"%d",item_drop_sets[index].chance[i+1]);
16942 edititemdropset_dlg[14+(i*3)].dp = chance[i+1];
16943 edititemdropset_dlg[15+(i*3)].dp = (void *) &item_list;
16944 sprintf(percent_str[i+1]," ");
16945 edititemdropset_dlg[16+(i*3)].dp = percent_str[i+1];
16946
16947 if(item_drop_sets[index].chance[i+1]==0)
16948 {
16949 edititemdropset_dlg[15+(i*3)].d1 = -2;
16950 }
16951 else
16952 {
16953 for(int32_t j=0; j<bii_cnt; j++)
16954 {
16955 if(bii[j].i == item_drop_sets[index].item[i])
16956 {
16957 edititemdropset_dlg[15+(i*3)].d1 = j;
16958 }
16959 }
16960 }
16961 }
16962
16963 large_dialog(edititemdropset_dlg);
16964
16965 int32_t ret = do_zqdialog(edititemdropset_dlg,-1);
16966
16967 if(ret==2)
16968 {
16969 saved=false;
16970
16971 sprintf(item_drop_sets[index].name,"%s",itemdropsetname);
16972
16973 item_drop_sets[index].chance[0]=atoi(chance[0]);
16974
16975 for(int32_t i=0; i<10; ++i)
16976 {
16977 item_drop_sets[index].chance[i+1]=atoi(chance[i+1]);
16978
16979 if(bii[edititemdropset_dlg[15+(i*3)].d1].i == -2)
16980 {
16981 item_drop_sets[index].chance[i+1]=0;
16982 }
16983 else
16984 {
16985 item_drop_sets[index].item[i] = bii[edititemdropset_dlg[15+(i*3)].d1].i;
16986 }
16987
16988 if(item_drop_sets[index].chance[i+1]==0)
16989 {
16990 item_drop_sets[index].item[i] = 0;
16991 }
16992 }
16993 }
16994 }
16995
16996 6 int32_t count_item_drop_sets()
16997 {
16998 6 int32_t count=0;
16999 6 bool found=false;
17000
17001
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1463 times.
1463 for(count=255; (count>0); --count)
17002 {
17003
2/2
✓ Branch 0 taken 1457 times.
✓ Branch 1 taken 16034 times.
17491 for(int32_t i=0; (i<11); ++i)
17004 {
17005
2/2
✓ Branch 0 taken 16028 times.
✓ Branch 1 taken 6 times.
16034 if(item_drop_sets[count].chance[i]!=0)
17006 {
17007 6 found=true;
17008 6 break;
17009 }
17010 16028 }
17011
17012
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 1457 times.
1463 if(found)
17013 {
17014 6 break;
17015 }
17016 1457 }
17017
17018 6 return count+1;
17019 }
17020
17021 int32_t onItemDropSets()
17022 {
17023 item_drop_set_list_size = MAXITEMDROPSETS;
17024
17025 int32_t index = select_data("Item Drop Sets",0,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
17026
17027 while(index!=-1)
17028 {
17029 EditItemDropSet(index);
17030 index = select_data("Item Drop Sets",index,itemdropsetlist,"Edit","Done",get_zc_font(font_lfont));
17031 }
17032
17033 return D_O_K;
17034 }
17035
17036 int32_t curr_ring = 0;
17037
17038 void EditWarpRingScr(int32_t ring,int32_t index)
17039 {
17040 char caption[40],buf[10];
17041 restore_mouse();
17042
17043 sprintf(caption,"Ring %d Warp %d",ring,index+1);
17044 warpring_warp_dlg[0].dp = (void *)caption;
17045 warpring_warp_dlg[0].dp2=get_zc_font(font_lfont);
17046
17047 sprintf(buf,"%02X",QMisc.warp[ring].scr[index]);
17048 warpring_warp_dlg[3].d1 = QMisc.warp[ring].dmap[index];
17049 warpring_warp_dlg[4].dp = buf;
17050 warpring_warp_dlg[8].dp = buf;
17051 warpring_warp_dlg[8].dp3 = &warpring_warp_dlg[3].d1;
17052
17053 vector<DIALOG*> dlgs;
17054 dlgs.push_back(&warpring_warp_dlg[3]);
17055 dlgs.push_back(&warpring_warp_dlg[4]);
17056 warpring_warp_dlg[8].dp2 = &dlgs;
17057
17058 dmap_list_size=MAXDMAPS;
17059 dmap_list_zero=true;
17060
17061 large_dialog(warpring_warp_dlg);
17062
17063 int32_t ret=do_zqdialog(warpring_warp_dlg,-1);
17064
17065 if(ret==5 || ret==6)
17066 {
17067 saved=false;
17068 QMisc.warp[ring].dmap[index] = warpring_warp_dlg[3].d1;
17069 QMisc.warp[ring].scr[index] = zc_xtoi(buf);
17070 }
17071
17072 if(ret==6)
17073 {
17074 Map.dowarp2(ring,index);
17075 refresh(rALL);
17076 }
17077 }
17078
17079 int32_t d_warplist_proc(int32_t msg,DIALOG *d,int32_t c)
17080 {
17081 if(msg==MSG_DRAW)
17082 {
17083 int32_t *xy = (int32_t*)(d->dp3);
17084 int32_t ring = curr_ring;
17085 int32_t dmap = QMisc.warp[ring].dmap[d->d1];
17086 float temp_scale = 1.5;
17087
17088 drawdmap(dmap);
17089
17090 if(xy[0]||xy[1])
17091 {
17092 int32_t x = d->x+int32_t((xy[0]-2)*temp_scale);
17093 int32_t y = d->y+int32_t((xy[1]-2)*temp_scale);
17094 int32_t w = 84;
17095 int32_t h = 52;
17096 jwin_draw_frame(screen,x,y,w,h,FR_DEEP);
17097 drawdmap_screen(x+2,y+2,w-4,h-4,dmap);
17098 }
17099
17100 if(xy[2]||xy[3])
17101 {
17102 textprintf_ex(screen,font,d->x+int32_t(xy[2]*temp_scale),d->y+int32_t(xy[3]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Map: %d ",DMaps[dmap].map+1);
17103 }
17104
17105 if(xy[4]||xy[5])
17106 {
17107 textprintf_ex(screen,font,d->x+int32_t(xy[4]*temp_scale),d->y+int32_t(xy[5]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Level:%2d ",DMaps[dmap].level);
17108 }
17109
17110 if(xy[6]||xy[7])
17111 {
17112 textprintf_ex(screen,font,d->x+int32_t(xy[6]*temp_scale),d->y+int32_t(xy[7]*temp_scale),jwin_pal[jcBOXFG],jwin_pal[jcBOX],"Scr: 0x%02X ",QMisc.warp[ring].scr[d->d1]);
17113 }
17114 }
17115
17116 return jwin_list_proc(msg,d,c);
17117 }
17118
17119 int32_t d_wclist_proc(int32_t msg,DIALOG *d,int32_t c)
17120 {
17121 int32_t d1 = d->d1;
17122 int32_t ret = jwin_droplist_proc(msg,d,c);
17123 QMisc.warp[curr_ring].size=d->d1+3;
17124
17125 if(d->d1 != d1)
17126 return D_CLOSE;
17127
17128 return ret;
17129 }
17130
17131 const char *wclist(int32_t index, int32_t *list_size)
17132 {
17133 static char buf[2];
17134
17135 if(index>=0)
17136 {
17137 if(index>6)
17138 index=6;
17139
17140 sprintf(buf,"%d",index+3);
17141 return buf;
17142 }
17143
17144 *list_size=7;
17145 return NULL;
17146 }
17147
17148 //int32_t warpringdmapxy[8] = {160,116,160,90,160,102,160,154};
17149 int32_t warpringdmapxy[8] = {80,26,80,0,80,12,80,78};
17150
17151 9 static ListData number_list(numberlist, &font);
17152 9 static ListData wc_list(wclist, &font);
17153
17154 static DIALOG warpring_dlg[] =
17155 {
17156 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
17157 9 { jwin_win_proc, 0, 0, 193, 166, vc(14), vc(1), 0, D_EXIT, 0, 0, NULL, NULL, NULL },
17158 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17159 9 { jwin_text_proc, 16, 33, 48, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Count:", NULL, NULL },
17160 9 { d_wclist_proc, 72, 29, 48, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &wc_list, NULL, NULL },
17161 // 4
17162 9 { d_warplist_proc, 16, 50, 65, 71, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &number_list, NULL, warpringdmapxy },
17163 9 { jwin_button_proc, 26, 140, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
17164 9 { jwin_button_proc, 106, 140, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
17165 9 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
17166 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17167 };
17168
17169 int32_t select_warp()
17170 {
17171 QMisc.warp[curr_ring].size = vbound(QMisc.warp[curr_ring].size,3,9);
17172 number_list_zero = false;
17173
17174 int32_t ret=4;
17175
17176 large_dialog(warpring_dlg);
17177
17178 do
17179 {
17180 number_list_size = QMisc.warp[curr_ring].size;
17181 warpring_dlg[3].d1 = QMisc.warp[curr_ring].size-3;
17182 ret = do_zqdialog(warpring_dlg,ret);
17183 }
17184 while(ret==3);
17185
17186 if(ret==6 || ret==0)
17187 {
17188 return -1;
17189 }
17190
17191 return warpring_dlg[4].d1;
17192 }
17193
17194 void EditWarpRing(int32_t ring)
17195 {
17196 char buf[40];
17197 sprintf(buf,"Ring %d Warps",ring);
17198 warpring_dlg[0].dp = buf;
17199 warpring_dlg[0].dp2 = get_zc_font(font_lfont);
17200 curr_ring = ring;
17201
17202 int32_t index = select_warp();
17203
17204 while(index!=-1)
17205 {
17206 EditWarpRingScr(ring,index);
17207 index = select_warp();
17208 }
17209 }
17210
17211 int32_t onWarpRings()
17212 {
17213 number_list_size = 9;
17214 number_list_zero = true;
17215
17216 int32_t index = select_data("Warp Rings",0,numberlist,"Edit","Done",get_zc_font(font_lfont));
17217
17218 while(index!=-1)
17219 {
17220 EditWarpRing(index);
17221 number_list_size = 9;
17222 number_list_zero = true;
17223 index = select_data("Warp Rings",index,numberlist,"Edit","Done",get_zc_font(font_lfont));
17224 }
17225
17226 return D_O_K;
17227 }
17228
17229 const char *enemy_viewer(int32_t index, int32_t *list_size)
17230 {
17231 if(index<0)
17232 {
17233 *list_size=10;
17234
17235 return NULL;
17236 }
17237
17238 int32_t guy=Map.CurrScr()->enemy[index];
17239
17240 if (guy == 0) return "(None)";
17241 return guy>=eSTART ? guy_string[guy] : (char *) "(Guy - Do Not Use!)";
17242 }
17243
17244 enemy_struct bie[eMAXGUYS];
17245 enemy_struct ce[100];
17246 int32_t enemy_type=0,bie_cnt=-1,ce_cnt;
17247
17248 enemy_struct big[zqMAXGUYS];
17249 enemy_struct cg[100];
17250 int32_t guy_type=0,big_cnt=-1,cg_cnt;
17251
17252 //Uses old_max_guys[] in zq_misc.cpp to define what are visible if bool hide is set true. -Z
17253 void build_bie_list(bool hide)
17254 {
17255 bie[0].s = (char *)"(None)";
17256 bie[0].i = 0;
17257 bie_cnt=1;
17258
17259 for(int32_t i=1; i<eMAXGUYS; i++)
17260 {
17261 if (i < eSTART) continue; // ignore guys - enemies only!
17262
17263 if(i >= OLDMAXGUYS || old_guy_string[i][strlen(old_guy_string[i])-1]!=' ' || !hide)
17264 {
17265 bie[bie_cnt].s = (char *)guy_string[i];
17266 bie[bie_cnt].i = i;
17267 ++bie_cnt;
17268 }
17269 }
17270
17271 for(int32_t i=1; i<bie_cnt-1; i++) //Start at 1 so '(None)' isn't alphabetized!
17272 {
17273 for(int32_t j=i+1; j<bie_cnt; j++)
17274 {
17275 if(strcmp(bie[i].s,bie[j].s)>0)
17276 {
17277 zc_swap(bie[i],bie[j]);
17278 }
17279 }
17280 }
17281 }
17282
17283 int32_t efrontfacingtile(int32_t id)
17284 {
17285 int32_t anim = get_qr(qr_NEWENEMYTILES)?guysbuf[id].e_anim:guysbuf[id].anim;
17286 int32_t usetile = 0;
17287
17288 switch(anim)
17289 {
17290
17291 case aNONE: break;
17292 case aAQUA:
17293 if(!(get_qr(qr_NEWENEMYTILES) && guysbuf[id].attributes[0]))
17294 break;
17295
17296 case aWALLM:
17297 case aGHOMA:
17298 usetile=1;
17299 break;
17300
17301 //Fallthrough
17302 case a2FRM4DIR:
17303 case aWALK:
17304 usetile=2;
17305 break;
17306
17307 case aLEV:
17308 case a3FRM4DIR:
17309 usetile=3;
17310 break;
17311
17312 case aLANM:
17313 usetile = !(get_qr(qr_NEWENEMYTILES))?0:4;
17314 break;
17315
17316 case aNEWDONGO:
17317 case a4FRM8EYE:
17318 case aNEWWIZZ:
17319 case aARMOS4:
17320 case aNEWTEK:
17321 case aNEWWALLM:
17322 case a4FRM4DIRF:
17323 case a4FRM4DIR:
17324 case a4FRM8DIRF:
17325 case a4FRMPOS8DIR:
17326 case a4FRMPOS8DIRF:
17327 case a4FRMPOS4DIR:
17328 case a4FRMPOS4DIRF:
17329 usetile=4;
17330 break;
17331
17332 case aDONGO:
17333 usetile=6;
17334 break;
17335
17336 case aDONGOBS:
17337 usetile=24;
17338 break;
17339
17340 case aNEWLEV:
17341 usetile=40;
17342 break;
17343
17344 case aNEWZORA:
17345 if(guysbuf[id].family==eeZORA)
17346 usetile=44;
17347
17348 break;
17349
17350 case aGLEEOK:
17351 if(!get_qr(qr_NEWENEMYTILES))
17352 usetile = (guysbuf[id].s_tile - guysbuf[id].tile)+1;
17353 else
17354 usetile = (guysbuf[id].attributes[7]);
17355
17356 break;
17357 }
17358
17359 return zc_max(get_qr(qr_NEWENEMYTILES) ? -guysbuf[id].e_tile
17360 : -guysbuf[id].tile, usetile);
17361 }
17362
17363 int32_t onEnemies()
17364 {
17365 call_screenenemies_dialog();
17366 refresh(rALL);
17367 return D_O_K;
17368 }
17369
17370 char author[65],title[65],password[32];
17371
17372 int32_t d_showedit_proc(int32_t msg,DIALOG *d,int32_t c)
17373 {
17374 int32_t ret = jwin_edit_proc(msg,d,c);
17375
17376 if(msg==MSG_DRAW)
17377 {
17378 (d+1)->proc(MSG_DRAW,d+1,0);
17379 }
17380
17381 return ret;
17382 }
17383
17384 int32_t onHeader()
17385 {
17386 call_header_dlg();
17387 return D_O_K;
17388 }
17389
17390 void call_cheats_dlg();
17391 int32_t onCheats()
17392 {
17393 call_cheats_dlg();
17394 return D_O_K;
17395 }
17396
17397 bool do_x_button(BITMAP *dest, int32_t x, int32_t y)
17398 {
17399 bool over=false;
17400
17401 while(gui_mouse_b())
17402 {
17403 custom_vsync();
17404
17405 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17406 {
17407 if(!over)
17408 {
17409 draw_x_button(dest, x, y, D_SELECTED);
17410 over=true;
17411 }
17412 }
17413 else
17414 {
17415 if(over)
17416 {
17417 draw_x_button(dest, x, y, 0);
17418 over=false;
17419 }
17420 }
17421 }
17422
17423 return over;
17424 }
17425
17426 bool do_question_button(BITMAP *dest, int32_t x, int32_t y)
17427 {
17428 bool over=false;
17429
17430 while(gui_mouse_b())
17431 {
17432 custom_vsync();
17433
17434 if(isinRect(gui_mouse_x(),gui_mouse_y(),x,y,x+15,y+13))
17435 {
17436 if(!over)
17437 {
17438 draw_question_button(dest, x, y, D_SELECTED);
17439 over=true;
17440 }
17441 }
17442 else
17443 {
17444 if(over)
17445 {
17446 draw_question_button(dest, x, y, 0);
17447 over=false;
17448 }
17449 }
17450 }
17451
17452 return over;
17453 }
17454
17455
17456 int32_t d_dummy_proc(int32_t,DIALOG *,int32_t)
17457 {
17458 return D_O_K;
17459 }
17460
17461 int32_t d_maptile_proc(int32_t msg, DIALOG *d, int32_t)
17462 {
17463 switch(msg)
17464 {
17465 case MSG_CLICK:
17466 if(select_tile(d->d1,d->d2,1,d->fg,true, 0, true))
17467 return D_REDRAW;
17468
17469 case MSG_DRAW:
17470 {
17471 int32_t dw = d->w;
17472 int32_t dh = d->h;
17473
17474 if(d->dp2==(void*)1)
17475 {
17476 dw /= 2;
17477 dh /= 2;
17478 }
17479
17480 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17481
17482 if(buf)
17483 {
17484 clear_bitmap(buf);
17485
17486 for(int32_t y=0; y<dh; y+=16)
17487 for(int32_t x=0; x<dw; x+=16)
17488 {
17489 if(d->d1)
17490 puttile16(buf,d->d1+(y>>4)*20+(x>>4),x,y,d->fg,0);
17491 }
17492
17493 if(d->dp2==(void*)1)
17494 stretch_blit(buf,screen,0,0,dw,dh,d->x-1,d->y-1,dw*2,dh*2);
17495 else
17496 blit(buf,screen,0,0,d->x,d->y,dw,dh);
17497
17498 destroy_bitmap(buf);
17499 }
17500 }
17501 }
17502
17503 return D_O_K;
17504 }
17505
17506 static int32_t last_combo=0;
17507 static int32_t last_cset=0;
17508
3/4
✓ Branch 0 taken 73728 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 73719 times.
✓ Branch 3 taken 9 times.
73728 static combo_alias temp_aliases[MAXCOMBOALIASES];
17509
17510 static char comboa_str_buf[32];
17511
17512 int32_t d_comboalist_proc(int32_t msg,DIALOG *d,int32_t c)
17513 {
17514 int32_t d1 = d->d1;
17515 int32_t ret = jwin_droplist_proc(msg,d,c);
17516 comboa_cnt = d->d1;
17517
17518 if(d1!=d->d1)
17519 {
17520 set_comboaradio(temp_aliases[comboa_cnt].layermask);
17521 return D_REDRAW;
17522 }
17523
17524 return ret;
17525 }
17526
17527 const char *comboalist(int32_t index, int32_t *list_size)
17528 {
17529 if(index>=0)
17530 {
17531 bound(index,0,MAXCOMBOALIASES-1);
17532 sprintf(comboa_str_buf,"%d",index);
17533 return comboa_str_buf;
17534 }
17535
17536 *list_size=MAXCOMBOALIASES;
17537 return NULL;
17538 }
17539
17540 extern int32_t scheme[jcMAX];
17541
17542 int32_t d_comboa_proc(int32_t msg,DIALOG *d,int32_t c)
17543 {
17544 //these are here to bypass compiler warnings about unused arguments
17545 c=c;
17546
17547 combo_alias *combo;
17548 combo = &temp_aliases[comboa_cnt];
17549 int32_t position;
17550 int32_t cur_layer, temp_layer;
17551 int32_t lay_count=0;
17552 int32_t size = 2;
17553
17554 int32_t cx1=(gui_mouse_x()-d->x-(120-(combo->width*8)));
17555 int32_t cy1=(gui_mouse_y()-d->y-(80-(combo->height*8)));
17556 int32_t cx=cx1/(16*size);
17557 int32_t cy=cy1/(16*size);
17558
17559 int32_t co,cs;
17560
17561
17562 switch(msg)
17563 {
17564 case MSG_CLICK:
17565 if((cx>combo->width)||(cx1<0))
17566 return D_O_K;
17567
17568 if((cy>combo->height)||(cy1<0))
17569 return D_O_K;
17570
17571 for(int32_t j=0; j<layer_cnt; j++)
17572 {
17573 if(combo->layermask&(1<<j))
17574 lay_count++;
17575 }
17576
17577 position=(lay_count)*(combo->width+1)*(combo->height+1);
17578 position+=(cy*(combo->width+1))+cx;
17579
17580 if(key[KEY_LSHIFT]||key[KEY_RSHIFT])
17581 {
17582 combo->combos[position] = 0;
17583 combo->csets[position] = 0;
17584
17585 while(gui_mouse_b())
17586 {
17587 /* do nothing */
17588 rest(1);
17589 }
17590
17591 return D_REDRAW;
17592 }
17593
17594 co=combo->combos[position];
17595 cs=combo->csets[position];
17596
17597 if((co==0)||(key[KEY_ZC_LCONTROL]))
17598 {
17599 co=last_combo;
17600 cs=last_cset;
17601 }
17602
17603 if((select_combo_2(co,cs)))
17604 {
17605 last_combo = co;
17606 last_cset = cs;
17607
17608 combo->combos[position]=co;
17609 combo->csets[position]=cs;
17610 }
17611
17612 return D_REDRAW;
17613 break;
17614
17615 case MSG_DRAW:
17616 BITMAP *buf = create_bitmap_ex(8,d->w,d->h);
17617
17618 if(buf)
17619 {
17620 clear_bitmap(buf);
17621
17622 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17623 {
17624 int32_t k=0;
17625 cur_layer=0;
17626 temp_layer=combo->layermask;
17627
17628 while((temp_layer!=0)&&(k<z))
17629 {
17630 if(temp_layer&1)
17631 {
17632 k++;
17633 }
17634
17635 cur_layer++;
17636 temp_layer = temp_layer>>1;
17637 }
17638
17639 for(int32_t y=0; (y<d->h)&&((y/16)<=combo->height); y+=16)
17640 {
17641 for(int32_t x=0; (x<d->w)&&((x/16)<=combo->width); x+=16)
17642 {
17643 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y/16)*(combo->width+1))+(x/16));
17644
17645 if(combo->combos[cpos])
17646 {
17647 if(!((d-1)->flags&D_SELECTED)||(cur_layer==layer_cnt))
17648 {
17649 if(z==0)
17650 {
17651 puttile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17652 }
17653 else
17654 {
17655 overtile16(buf,combobuf[combo->combos[cpos]].tile,x,y,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17656 }
17657 }
17658 }
17659 }
17660 }
17661 }
17662
17663 rectfill(screen, d->x-2,d->y-2,d->x+256+2,d->y+176+2,jwin_pal[jcBOX]);
17664 int32_t dx = 120-(combo->width*8)+d->x;
17665 int32_t dy = 80-(combo->height*8)+d->y;
17666 stretch_blit(buf,screen,0,0,(combo->width+1)*16,(combo->height+1)*16,dx,dy,(combo->width+1)*16*size,(combo->height+1)*16*size);
17667 //blit(buf,screen,0,0,120-(combo->width*8)+d->x,80-(combo->height*8)+d->y,(combo->width+1)*16,(combo->height+1)*16);
17668 (d-11)->w = (combo->width+1)*16*size+2;
17669 (d-11)->h = (combo->height+1)*16*size+2;
17670 (d-11)->x = 120-(combo->width*8)+4*size+2+(d-14)->x;
17671 (d-11)->y = 80-(combo->height*8)+25*size+2+(d-14)->y;
17672 object_message((d-11),MSG_DRAW,0);
17673
17674 destroy_bitmap(buf);
17675 }
17676
17677 break;
17678 }
17679
17680 return D_O_K;
17681 }
17682
17683 void draw_combo_alias_thumbnail(BITMAP *dest, combo_alias const* combo, int32_t x, int32_t y, int32_t size)
17684 {
17685 if(!combo->combo)
17686 {
17687 int32_t cur_layer, temp_layer;
17688
17689 int32_t cw=combo->width+1;
17690 int32_t ch=combo->height+1;
17691 int32_t dw=cw<<4;
17692 int32_t dh=ch<<4;
17693 int32_t sw=16, sh=16, sx=0, sy=0;
17694
17695 if(cw<ch)
17696 {
17697 sw=((cw<<4)/ch);
17698 sx=((16-sw)>>1);
17699 }
17700 else
17701 {
17702 sh=((ch<<4)/cw);
17703 sy=((16-sh)>>1);
17704 }
17705
17706 BITMAP *buf = create_bitmap_ex(8,dw,dh);
17707 BITMAP *buf2 = create_bitmap_ex(8, 16*size, 16*size);
17708 clear_bitmap(buf);
17709 clear_bitmap(buf2);
17710
17711 if(buf&&(combo->width>0||combo->height>0||combo->combos[0]>0))
17712 {
17713 clear_bitmap(buf);
17714
17715 for(int32_t z=0; z<=comboa_lmasktotal(combo->layermask); z++)
17716 {
17717 int32_t k=0;
17718 cur_layer=0;
17719 temp_layer=combo->layermask;
17720
17721 while((temp_layer!=0)&&(k<z))
17722 {
17723 if(temp_layer&1)
17724 {
17725 k++;
17726 }
17727
17728 cur_layer++;
17729 temp_layer = temp_layer>>1;
17730 }
17731
17732 for(int32_t y2=0; (y2<dh)&&((y2>>4)<=combo->height); y2+=16)
17733 {
17734 for(int32_t x2=0; (x2<dw)&&((x2>>4)<=combo->width); x2+=16)
17735 {
17736 int32_t cpos = (z*(combo->width+1)*(combo->height+1))+(((y2/16)*(combo->width+1))+(x2/16));
17737
17738 if(combo->combos[cpos])
17739 {
17740 if(z==0)
17741 {
17742 puttile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17743 }
17744 else
17745 {
17746 overtile16(buf,combobuf[combo->combos[cpos]].tile,x2,y2,combo->csets[cpos],combobuf[combo->combos[cpos]].flip);
17747 }
17748 }
17749 }
17750 }
17751 }
17752
17753 stretch_blit(buf, buf2, 0, 0, (cw*16), (ch*16), sx*size, sy*size, sw*size, sh*size);
17754 blit(buf2, dest, 0, 0, x, y, 16*size, 16*size);
17755 }
17756 else
17757 {
17758 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17759 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17760 }
17761
17762 if(buf)
17763 destroy_bitmap(buf);
17764
17765 if(buf2)
17766 destroy_bitmap(buf2);
17767 }
17768 else
17769 {
17770 if(combobuf[combo->combo].tile>0)
17771 {
17772 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17773 put_combo(dest, x, y, combo->combo, combo->cset, 0, 0, size);
17774 }
17775 else
17776 {
17777 rectfill(dest,x,y,x+16*size-1,y+16*size-1,0);
17778 rectfill(dest,x+3*size,y+3*size,x+12*size,y+12*size,vc(4));
17779 }
17780 }
17781 }
17782
17783 int32_t d_comboat_proc(int32_t msg,DIALOG *d,int32_t)
17784 {
17785 switch(msg)
17786 {
17787 case MSG_CLICK:
17788 {
17789 int32_t c2;
17790 int32_t cs;
17791 c2=temp_aliases[comboa_cnt].combo;
17792 cs=temp_aliases[comboa_cnt].cset;
17793
17794 if(gui_mouse_b()&2) //right mouse button
17795 {
17796 if(c2==0&&cs==0&&!(gui_mouse_b()&1))
17797 {
17798 return D_O_K;
17799 }
17800
17801 temp_aliases[comboa_cnt].combo=0;
17802 temp_aliases[comboa_cnt].cset=0;
17803 }
17804
17805 if(gui_mouse_b()&1) //left mouse button
17806 {
17807 if(select_combo_2(c2, cs))
17808 {
17809 temp_aliases[comboa_cnt].combo=c2;
17810 temp_aliases[comboa_cnt].cset=cs;
17811 }
17812
17813 return D_REDRAW;
17814 }
17815 else
17816 {
17817 return D_REDRAWME;
17818 }
17819 }
17820 break;
17821
17822 case MSG_DRAW:
17823 draw_combo_alias_thumbnail(screen, &temp_aliases[comboa_cnt], d->x-1, d->y-1,2);
17824 break;
17825
17826 default:
17827 break;
17828 }
17829
17830 return D_O_K;
17831 }
17832
17833 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c);
17834
17835 static DIALOG orgcomboa_dlg[] =
17836 {
17837 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17838 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Organize Combo Aliases", NULL, NULL },
17839 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17840 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17841
17842 { jwin_radio_proc, 10, 40, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Copy", NULL, NULL },
17843 { jwin_text_proc, 10, 50, 33, 9, 0, 0, 0, 0, 0, 0, (void *) "", NULL, NULL },
17844 // { jwin_radio_proc, 10, 50, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Move", NULL, NULL },
17845 { jwin_radio_proc, 10, 60, 33, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Swap", NULL, NULL },
17846 /* 6 */ { jwin_edit_proc, 110, 35, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17847 { jwin_edit_proc, 110, 55, 32, 16, vc(12), vc(1), 0, 0, 4, 0, NULL, NULL, NULL },
17848 { jwin_text_proc, 60, 40, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Source", NULL, NULL },
17849 { jwin_text_proc, 60, 60, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Dest", NULL, NULL},
17850 { jwin_radio_proc, 10, 80, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Insert new (before source)", NULL, NULL },
17851 { jwin_radio_proc, 10, 100, 60, 9, vc(14), vc(1), 0, 0, 0, 0, (void*) "Delete source", NULL, NULL },
17852 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17853 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17854 };
17855
17856 static DIALOG newcomboa_dlg[] =
17857 {
17858 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
17859 { jwin_win_proc, 0, 0, 200, 161, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Properties", NULL, NULL },
17860 { jwin_button_proc, 27, 130, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
17861 { jwin_button_proc, 112, 130, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
17862 { jwin_text_proc, 24, 34, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Width", NULL, NULL },
17863 { jwin_text_proc, 24, 52, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Alias Height", NULL, NULL },
17864 { jwin_text_proc, 24, 70, 100, 8, 0, 0, 0, 0, 0, 0, (void *) "Layers to Draw On:", NULL, NULL },
17865 { jwin_edit_proc, 104, 30, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17866 { jwin_edit_proc, 122, 48, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17867 { jwin_check_proc, 24, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "1", NULL, NULL },
17868 { jwin_check_proc, 50, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "2", NULL, NULL },
17869 { jwin_check_proc, 76, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "3", NULL, NULL },
17870 { jwin_check_proc, 102, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "4", NULL, NULL },
17871 { jwin_check_proc, 128, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "5", NULL, NULL },
17872 { jwin_check_proc, 154, 86, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "6", NULL, NULL },
17873
17874
17875 // { jwin_text_proc, 24, 106, 80, 8, 0, 0, 0, 0, 0, 0, (void *) "Copy to :", NULL, NULL },
17876 //15
17877 // { jwin_edit_proc, 100, 100, 28-6, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
17878 // { jwin_check_proc, 84, 106, 24, 9, vc(12), vc(1), 0, 0, 1, 0, (void *) "", NULL, NULL },
17879
17880 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
17881 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
17882 };
17883
17884 bool swapComboAlias(int32_t source, int32_t dest)
17885 {
17886 if(source==dest)
17887 return false;
17888 zc_swap(temp_aliases[source],temp_aliases[dest]);
17889 return true;
17890 }
17891
17892
17893 bool copyComboAlias(int32_t source, int32_t dest)
17894 {
17895 if(source == dest)
17896 return false;
17897 temp_aliases[dest] = temp_aliases[source];
17898 return true;
17899 }
17900
17901 int32_t getcurrentcomboalias();
17902
17903 int32_t onOrgComboAliases()
17904 {
17905 char cSrc[8];
17906 char cDest[8];
17907 sprintf(cSrc,"%d", getcurrentcomboalias());
17908 strcpy(cDest,cSrc);
17909 int32_t iSrc = 0;
17910 int32_t iDest = 0;
17911
17912 //sprintf(cSrc,"0");
17913 //sprintf(cDest,"0");
17914 orgcomboa_dlg[0].dp2=get_zc_font(font_lfont);
17915 orgcomboa_dlg[6].dp= cSrc;
17916 orgcomboa_dlg[7].dp= cDest;
17917 int32_t ret = 1;
17918 large_dialog(orgcomboa_dlg);
17919 do
17920 {
17921 iSrc = atoi((char*)orgcomboa_dlg[6].dp);
17922 iDest = atoi((char*)orgcomboa_dlg[7].dp);
17923 ret = do_zqdialog(orgcomboa_dlg,-1);
17924
17925 if(ret!=1) return ret;
17926
17927 if((atoi((char*) orgcomboa_dlg[6].dp))<0 || (atoi((char*) orgcomboa_dlg[6].dp)) > MAXCOMBOALIASES-1)
17928 {
17929 char buf[100];
17930 snprintf(buf, 100, "Invalid source (range 0-%d)", MAXCOMBOALIASES-1);
17931 buf[99]='\0';
17932 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17933 ret = 1;
17934 }
17935
17936 // 10,11=ins, del
17937 if(orgcomboa_dlg[10].flags & D_SELECTED) //insert
17938 {
17939 for(int32_t j=MAXCOMBOALIASES-1; j>(atoi((char*) orgcomboa_dlg[6].dp)); --j)
17940 copyComboAlias(j-1,j);
17941 ret = -1;
17942 }
17943
17944 if(orgcomboa_dlg[11].flags & D_SELECTED) //delete
17945 {
17946 for(int32_t j=(atoi((char*) orgcomboa_dlg[6].dp)); j<MAXCOMBOALIASES-1; ++j)
17947 copyComboAlias(j+1,j);
17948 ret = -1;
17949 }
17950
17951 if((atoi((char*) orgcomboa_dlg[6].dp)) == (atoi((char*) orgcomboa_dlg[7].dp)))
17952 {
17953 jwin_alert("Error","Source and dest can't be the same.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17954 ret = 1;
17955 }
17956
17957 if((atoi((char*) orgcomboa_dlg[7].dp)) < 0 || (atoi((char*) orgcomboa_dlg[7].dp)) > MAXCOMBOALIASES-1)
17958 {
17959 char buf[100];
17960 snprintf(buf, 100, "Invalid dest (range 0-%d)", MAXCOMBOALIASES-1);
17961 buf[99]='\0';
17962
17963 jwin_alert("Error",buf,NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
17964 ret = 1;
17965 }
17966
17967 if(orgcomboa_dlg[3].flags & D_SELECTED) //copy
17968 {
17969 copyComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
17970 ret = -1;
17971 }
17972
17973 if(orgcomboa_dlg[5].flags & D_SELECTED) //swap
17974 {
17975 swapComboAlias((atoi((char*) orgcomboa_dlg[6].dp)),(atoi((char*) orgcomboa_dlg[7].dp)));
17976 ret = -1;
17977 }
17978 }
17979 while(ret==1);
17980 return ret;
17981 }
17982
17983 int32_t onNewComboAlias()
17984 {
17985 combo_alias *combo;
17986 combo = &temp_aliases[comboa_cnt];
17987
17988 char cwidth[5];
17989 char cheight[5];
17990 // char cp[3];
17991
17992 word temp_combos[16*11*7];
17993 byte temp_csets[16*11*7];
17994 sprintf(cwidth, "%d", combo->width+1);
17995 sprintf(cheight, "%d", combo->height+1);
17996 int32_t old_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
17997 int32_t old_width=combo->width;
17998 int32_t old_height=combo->height;
17999 int32_t oldlayer=combo->layermask;
18000
18001 for(int32_t i=0; i<old_count; i++)
18002 {
18003 temp_csets[i] = combo->csets[i];
18004 temp_combos[i] = combo->combos[i];
18005 }
18006
18007 newcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
18008 newcomboa_dlg[6].dp = cwidth;
18009 newcomboa_dlg[7].dp = cheight;
18010 newcomboa_dlg[8].flags = (combo->layermask&1)? D_SELECTED : 0;
18011 newcomboa_dlg[9].flags = (combo->layermask&2)? D_SELECTED : 0;
18012 newcomboa_dlg[10].flags = (combo->layermask&4)? D_SELECTED : 0;
18013 newcomboa_dlg[11].flags = (combo->layermask&8)? D_SELECTED : 0;
18014 newcomboa_dlg[12].flags = (combo->layermask&16)? D_SELECTED : 0;
18015 newcomboa_dlg[13].flags = (combo->layermask&32)? D_SELECTED : 0;
18016
18017 large_dialog(newcomboa_dlg);
18018
18019 int32_t ret = do_zqdialog(newcomboa_dlg,-1);
18020
18021 if(ret==1)
18022 {
18023 combo->width = ((atoi(cwidth)-1)<16)?zc_max(0,(atoi(cwidth)-1)):15;
18024 combo->height = ((atoi(cheight)-1)<11)?zc_max(0,(atoi(cheight)-1)):10;
18025 combo->layermask=0;
18026 combo->layermask |= (newcomboa_dlg[8].flags&D_SELECTED)?1:0;
18027 combo->layermask |= (newcomboa_dlg[9].flags&D_SELECTED)?2:0;
18028 combo->layermask |= (newcomboa_dlg[10].flags&D_SELECTED)?4:0;
18029 combo->layermask |= (newcomboa_dlg[11].flags&D_SELECTED)?8:0;
18030 combo->layermask |= (newcomboa_dlg[12].flags&D_SELECTED)?16:0;
18031 combo->layermask |= (newcomboa_dlg[13].flags&D_SELECTED)?32:0;
18032
18033 int32_t new_count = (comboa_lmasktotal(combo->layermask)+1)*(combo->width+1)*(combo->height+1);
18034
18035 combo->combos.clear();
18036 combo->csets.clear();
18037
18038 int32_t j=1;
18039 int32_t old_size=(old_width+1)*(old_height+1);
18040 int32_t new_start[7] =
18041 {
18042 0,
18043 ((combo->width+1)*(combo->height+1)*(1)),
18044 ((combo->width+1)*(combo->height+1)*(2)),
18045 ((combo->width+1)*(combo->height+1)*(3)),
18046 ((combo->width+1)*(combo->height+1)*(4)),
18047 ((combo->width+1)*(combo->height+1)*(5)),
18048 ((combo->width+1)*(combo->height+1)*(6))
18049 };
18050 int32_t new_layers[6] = {0,0,0,0,0,0};
18051 int32_t temp_layer = combo->layermask;
18052 int32_t temp_old = oldlayer;
18053 int32_t old_layers[6] = {0,0,0,0,0,0};
18054 int32_t k=1;
18055
18056 for(int32_t i=0; (i<6)&&(temp_layer!=0); j++,temp_layer>>=1,temp_old>>=1)
18057 {
18058 if(temp_layer&1)
18059 {
18060 new_layers[i] = j;
18061 //if(oldlayer&(1<<(j-1))) old_layers[i] = k++;
18062 i++;
18063 }
18064
18065 if(temp_old&1)
18066 {
18067 if(temp_layer&1)
18068 {
18069 old_layers[i-1] = k;
18070 }
18071
18072 k++;
18073 }
18074 }
18075
18076 for(int32_t i=0; i<new_count; i++)
18077 {
18078 if(i>=new_start[6])
18079 {
18080 //oldl=oldlayer>>(new_layers[5]-1);
18081 j=i-new_start[6];
18082
18083 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[5]-1))))
18084 {
18085 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18086 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[5])];
18087 }
18088 else
18089 {
18090 combo->combos[i] = 0;
18091 combo->csets[i] = 0;
18092 }
18093 }
18094 else if(i>=new_start[5])
18095 {
18096 //oldl=oldlayer>>(new_layers[4]-1);
18097 j=i-new_start[5];
18098
18099 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[4]-1))))
18100 {
18101 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18102 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[4])];
18103 }
18104 else
18105 {
18106 combo->combos[i] = 0;
18107 combo->csets[i] = 0;
18108 }
18109 }
18110 else if(i>=new_start[4])
18111 {
18112 //oldl=oldlayer>>(new_layers[3]-1);
18113 j=i-new_start[4];
18114
18115 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[3]-1))))
18116 {
18117 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18118 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[3])];
18119 }
18120 else
18121 {
18122 combo->combos[i] = 0;
18123 combo->csets[i] = 0;
18124 }
18125 }
18126 else if(i>=new_start[3])
18127 {
18128 //oldl=oldlayer>>(new_layers[2]-1);
18129 j=i-new_start[3];
18130
18131 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[2]-1))))
18132 {
18133 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18134 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[2])];
18135 }
18136 else
18137 {
18138 combo->combos[i] = 0;
18139 combo->csets[i] = 0;
18140 }
18141 }
18142 else if(i>=new_start[2])
18143 {
18144 //oldl=oldlayer>>(new_layers[1]-1);
18145 j=i-new_start[2];
18146
18147 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[1]-1))))
18148 {
18149 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18150 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[1])];
18151 }
18152 else
18153 {
18154 combo->combos[i] = 0;
18155 combo->csets[i] = 0;
18156 }
18157 }
18158 else if(i>=new_start[1])
18159 {
18160 //oldl=oldlayer>>(new_layers[0]-1);
18161 j=i-new_start[1];
18162
18163 if(((j/(combo->width+1))<=old_height)&&((j%(combo->width+1))<=old_width)&&(oldlayer&(1<<(new_layers[0]-1))))
18164 {
18165 combo->combos[i] = temp_combos[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18166 combo->csets[i] = temp_csets[((j%(combo->width+1))+((old_width+1)*(j/(combo->width+1))))+(old_size*old_layers[0])];
18167 }
18168 else
18169 {
18170 combo->combos[i] = 0;
18171 combo->csets[i] = 0;
18172 }
18173 }
18174 else if(i>=new_start[0])
18175 {
18176 if(((i/(combo->width+1))<=old_height)&&((i%(combo->width+1))<=old_width))
18177 {
18178 combo->combos[i] = temp_combos[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18179 combo->csets[i] = temp_csets[(i%(combo->width+1))+((old_width+1)*(i/(combo->width+1)))];
18180 }
18181 else
18182 {
18183 combo->combos[i] = 0;
18184 combo->csets[i] = 0;
18185 }
18186 }
18187 }
18188
18189 set_comboaradio(combo->layermask);
18190 }
18191
18192 return ret;
18193 }
18194
18195 int32_t d_orgcomboa_proc(int32_t msg, DIALOG *d, int32_t c)
18196 {
18197 //these are here to bypass compiler warnings about unused arguments
18198 c=c;
18199
18200 int32_t down=0;
18201 int32_t selected=(d->flags&D_SELECTED)?1:0;
18202 int32_t last_draw;
18203
18204 switch(msg)
18205 {
18206
18207 case MSG_DRAW:
18208 {
18209 FONT *tfont=font;
18210 font=get_zc_font(font_lfont_l);
18211 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18212 font=tfont;
18213 }
18214 break;
18215
18216 case MSG_WANTFOCUS:
18217 return D_WANTFOCUS;
18218
18219 case MSG_KEY:
18220 /* close dialog? */
18221 onOrgComboAliases();
18222 return D_REDRAW;
18223
18224 /* or just toggle */
18225 /*d->flags ^= D_SELECTED;
18226 object_message(d, MSG_DRAW, 0);
18227 break;*/
18228
18229 case MSG_CLICK:
18230 last_draw = 0;
18231
18232 /* track the mouse until it is released */
18233 while(gui_mouse_b())
18234 {
18235 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18236
18237 /* redraw? */
18238 if(last_draw != down)
18239 {
18240 if(down != selected)
18241 d->flags |= D_SELECTED;
18242 else
18243 d->flags &= ~D_SELECTED;
18244
18245 object_message(d, MSG_DRAW, 0);
18246 last_draw = down;
18247 }
18248
18249 /* let other objects continue to animate */
18250 broadcast_dialog_message(MSG_IDLE, 0);
18251 }
18252
18253 /* redraw in normal state */
18254 if(down)
18255 {
18256 if(d->flags&D_EXIT)
18257 {
18258 d->flags &= ~D_SELECTED;
18259 object_message(d, MSG_DRAW, 0);
18260 }
18261 }
18262
18263 /* should we close the dialog? */
18264 if(down)
18265 {
18266 onOrgComboAliases();
18267 return D_REDRAW;
18268 }
18269
18270 break;
18271 }
18272
18273 return D_O_K;
18274 }
18275
18276 int32_t d_comboabutton_proc(int32_t msg, DIALOG *d, int32_t c)
18277 {
18278 //these are here to bypass compiler warnings about unused arguments
18279 c=c;
18280
18281 int32_t down=0;
18282 int32_t selected=(d->flags&D_SELECTED)?1:0;
18283 int32_t last_draw;
18284
18285 switch(msg)
18286 {
18287
18288 case MSG_DRAW:
18289 {
18290 FONT *tfont=font;
18291 font=get_zc_font(font_lfont_l);
18292 jwin_draw_text_button(screen, d->x, d->y, d->w, d->h, (char*)d->dp, d->flags, true);
18293 font=tfont;
18294 }
18295 break;
18296
18297 case MSG_WANTFOCUS:
18298 return D_WANTFOCUS;
18299
18300 case MSG_KEY:
18301 /* close dialog? */
18302 onNewComboAlias();
18303 return D_REDRAW;
18304
18305 /* or just toggle */
18306 /*d->flags ^= D_SELECTED;
18307 object_message(d, MSG_DRAW, 0);
18308 break;*/
18309
18310 case MSG_CLICK:
18311 last_draw = 0;
18312
18313 /* track the mouse until it is released */
18314 while(gui_mouse_b())
18315 {
18316 down = mouse_in_rect(d->x, d->y, d->w, d->h);
18317
18318 /* redraw? */
18319 if(last_draw != down)
18320 {
18321 if(down != selected)
18322 d->flags |= D_SELECTED;
18323 else
18324 d->flags &= ~D_SELECTED;
18325
18326 object_message(d, MSG_DRAW, 0);
18327 last_draw = down;
18328 }
18329
18330 /* let other objects continue to animate */
18331 broadcast_dialog_message(MSG_IDLE, 0);
18332 }
18333
18334 /* redraw in normal state */
18335 if(down)
18336 {
18337 if(d->flags&D_EXIT)
18338 {
18339 d->flags &= ~D_SELECTED;
18340 object_message(d, MSG_DRAW, 0);
18341 }
18342 }
18343
18344 /* should we close the dialog? */
18345 if(down)
18346 {
18347 onNewComboAlias();
18348 return D_REDRAW;
18349 }
18350
18351 break;
18352 }
18353
18354 return D_O_K;
18355 }
18356
18357 int32_t d_comboacheck_proc(int32_t msg, DIALOG *d, int32_t c)
18358 {
18359 int32_t temp = d->flags&D_SELECTED;
18360 int32_t ret=jwin_checkfont_proc(msg,d,c);
18361
18362 if(temp != (d->flags&D_SELECTED))
18363 {
18364 return D_REDRAW;
18365 }
18366
18367 return ret;
18368 }
18369
18370 9 static ListData comboa_list(comboalist, &font);
18371
18372 static DIALOG editcomboa_dlg[] =
18373 {
18374 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
18375 { jwin_win_proc, 0, 0, 320, 240, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Combo Alias Edit", NULL, NULL },
18376 { jwin_button_proc, 148, 212, 61, 21, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "O&K", NULL, NULL },
18377 { jwin_button_proc, 232, 212, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
18378 { jwin_frame_proc, 4+121, 28+81, 1, 1, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18379 { d_comboabutton_proc, 25, 212, 81, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Properties", NULL, NULL },
18380 { d_dummy_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18381 { d_comboa_radio_proc, 285, 44, 30, 8+1, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "0", NULL, NULL },
18382 { d_comboa_radio_proc, 285, 54, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
18383 { d_comboa_radio_proc, 285, 64, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
18384 { d_comboa_radio_proc, 285, 74, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
18385 { d_comboa_radio_proc, 285, 84, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
18386
18387 { d_comboa_radio_proc, 285, 94, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
18388 { d_comboa_radio_proc, 285, 104, 30, 8+1, vc(14), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
18389 { d_comboacheck_proc, 285, 164, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
18390 { d_comboa_proc, 6, 27, 256, 176, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18391 { jwin_ctext_proc, 290, 176, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Only Show", NULL, NULL },
18392 { jwin_ctext_proc, 290, 186, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Current", NULL, NULL },
18393 { jwin_ctext_proc, 290, 196, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Layer", NULL, NULL },
18394 { jwin_ctext_proc, 290, 122, 27, 8, 0, 0, 0, 0, 0, 0, (void *) "Thumbnail", NULL, NULL },
18395 { jwin_frame_proc, 280, 132, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18396 { d_comboat_proc, 282, 134, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18397
18398 //21
18399 { d_orgcomboa_proc, 106, 212, 21, 21, vc(14), vc(1), 'p', D_EXIT, 0, 0, (void *) "&Org", NULL, NULL },
18400 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18401 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18402 };
18403
18404 int32_t getcurrentcomboalias()
18405 {
18406 return editcomboa_dlg[5].d1;
18407 }
18408
18409 int32_t d_comboa_radio_proc(int32_t msg,DIALOG *d,int32_t c)
18410 {
18411 int32_t temp = layer_cnt;
18412 int32_t ret = jwin_radiofont_proc(msg,d,c);
18413
18414 if(editcomboa_dlg[6].flags&D_SELECTED) layer_cnt=0;
18415 else if(editcomboa_dlg[7].flags&D_SELECTED) layer_cnt=1;
18416 else if(editcomboa_dlg[8].flags&D_SELECTED) layer_cnt=2;
18417 else if(editcomboa_dlg[9].flags&D_SELECTED) layer_cnt=3;
18418 else if(editcomboa_dlg[10].flags&D_SELECTED) layer_cnt=4;
18419 else if(editcomboa_dlg[11].flags&D_SELECTED) layer_cnt=5;
18420 else if(editcomboa_dlg[12].flags&D_SELECTED) layer_cnt=6;
18421
18422 if(temp != layer_cnt)
18423 {
18424 return D_REDRAW;
18425 }
18426
18427 return ret;
18428 }
18429
18430 int32_t set_comboaradio(byte layermask)
18431 {
18432 if(editcomboa_dlg[7].flags&D_SELECTED) editcomboa_dlg[7].flags &= ~D_SELECTED;
18433
18434 if(editcomboa_dlg[8].flags&D_SELECTED) editcomboa_dlg[8].flags &= ~D_SELECTED;
18435
18436 if(editcomboa_dlg[9].flags&D_SELECTED) editcomboa_dlg[9].flags &= ~D_SELECTED;
18437
18438 if(editcomboa_dlg[10].flags&D_SELECTED) editcomboa_dlg[10].flags &= ~D_SELECTED;
18439
18440 if(editcomboa_dlg[11].flags&D_SELECTED) editcomboa_dlg[11].flags &= ~D_SELECTED;
18441
18442 if(editcomboa_dlg[12].flags&D_SELECTED) editcomboa_dlg[12].flags &= ~D_SELECTED;
18443
18444 if(!(layermask&1)) editcomboa_dlg[7].flags |= D_DISABLED;
18445 else editcomboa_dlg[7].flags &= ~D_DISABLED;
18446
18447 if(!(layermask&2)) editcomboa_dlg[8].flags |= D_DISABLED;
18448 else editcomboa_dlg[8].flags &= ~D_DISABLED;
18449
18450 if(!(layermask&4)) editcomboa_dlg[9].flags |= D_DISABLED;
18451 else editcomboa_dlg[9].flags &= ~D_DISABLED;
18452
18453 if(!(layermask&8)) editcomboa_dlg[10].flags |= D_DISABLED;
18454 else editcomboa_dlg[10].flags &= ~D_DISABLED;
18455
18456 if(!(layermask&16)) editcomboa_dlg[11].flags |= D_DISABLED;
18457 else editcomboa_dlg[11].flags &= ~D_DISABLED;
18458
18459 if(!(layermask&32)) editcomboa_dlg[12].flags |= D_DISABLED;
18460 else editcomboa_dlg[12].flags &= ~D_DISABLED;
18461
18462 editcomboa_dlg[6].flags |= D_SELECTED;
18463 layer_cnt=0;
18464 return 1;
18465 }
18466
18467 int32_t onEditComboPool()
18468 {
18469 call_cpool_dlg(combo_pool_pos);
18470 return D_O_K;
18471 }
18472 int32_t onEditAutoCombo()
18473 {
18474 call_autocombo_dlg(combo_auto_pos);
18475 return D_O_K;
18476 }
18477 int32_t onEditComboAlias()
18478 {
18479 comboa_cnt = combo_apos;
18480 reset_combo_animations();
18481 reset_combo_animations2();
18482
18483 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18484 temp_aliases[i] = combo_aliases[i];
18485
18486 editcomboa_dlg[0].dp2 = get_zc_font(font_lfont);
18487 set_comboaradio(temp_aliases[comboa_cnt].layermask);
18488 editcomboa_dlg[5].d1 = comboa_cnt;
18489
18490 bool small_d1 = editcomboa_dlg[0].d1==0;
18491 large_dialog(editcomboa_dlg,2);
18492
18493 if(small_d1)
18494 {
18495 for(int32_t i=6; i<=12; i++)
18496 {
18497 editcomboa_dlg[i].w=30*1.5;
18498 editcomboa_dlg[i].h=9*1.5;
18499 }
18500
18501 editcomboa_dlg[13].w=17*1.5;
18502 editcomboa_dlg[13].h=9*1.5;
18503 editcomboa_dlg[4].w=81*1.5;
18504 editcomboa_dlg[4].h=21*1.5;
18505 editcomboa_dlg[4].dp2=get_zc_font(font_lfont_l);
18506 editcomboa_dlg[21].w=21*1.5;
18507 editcomboa_dlg[21].h=21*1.5;
18508 editcomboa_dlg[21].dp2=get_zc_font(font_lfont_l);
18509 }
18510
18511 int32_t ret=do_zqdialog(editcomboa_dlg,-1);
18512
18513 if(ret==1)
18514 {
18515 saved=false;
18516
18517 for(int32_t i=0; i<MAXCOMBOALIASES; i++)
18518 combo_aliases[i] = temp_aliases[i];
18519 }
18520
18521 setup_combo_animations();
18522 setup_combo_animations2();
18523 return D_O_K;
18524 }
18525 void call_calias_dlg(int index)
18526 {
18527 combo_apos = comboa_cnt = index;
18528 onEditComboAlias();
18529 }
18530
18531 static char ffcombo_str_buf[MAXFFCS];
18532 static char fflink_str_buf[MAXFFCS];
18533
18534 BITMAP* ffcur;
18535
18536 const char *ffcombolist(int32_t index, int32_t *list_size)
18537 {
18538 if(index>=0)
18539 {
18540 bound(index,0,MAXFFCS-1);
18541 sprintf(ffcombo_str_buf,"%d",index+1);
18542 return ffcombo_str_buf;
18543 }
18544
18545 *list_size=MAXFFCS;
18546 return NULL;
18547 }
18548
18549 9 static ListData ffcombo_list(ffcombolist, &font);
18550
18551 static DIALOG ffcombo_sel_dlg[] =
18552 {
18553 9 { jwin_win_proc, 0, 0, 200, 179, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Choose Freeform Combo", NULL, NULL },
18554 9 { jwin_button_proc, 35, 152, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Edit", NULL, NULL },
18555 9 { jwin_button_proc, 104, 152, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
18556 9 { d_ffcombolist_proc, 11, 24, 49, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 1, 0, (void *) &ffcombo_list, NULL, NULL },
18557 9 { d_comboframe_proc, 68, 23, 20, 20, 0, 0, 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
18558 9 { d_bitmap_proc, 70, 25, 16, 16, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18559 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
18560 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
18561 };
18562
18563 int32_t d_ffcombolist_proc(int32_t msg,DIALOG *d,int32_t c)
18564 {
18565 int32_t ret = jwin_droplist_proc(msg,d,c);
18566 int32_t d1 = d->d1;
18567 int32_t x=ffcombo_sel_dlg[0].x;
18568 int32_t y=ffcombo_sel_dlg[0].y;
18569 FONT *tempfont=(font);
18570 int32_t x2=text_length(tempfont, "Move Delay:")+4;
18571
18572 switch(msg)
18573 {
18574 case MSG_DRAW:
18575 if(!ffcur) return D_O_K;
18576
18577 BITMAP *buf = create_bitmap_ex(8,16,16);
18578
18579 if(buf)
18580 {
18581 clear_bitmap(buf);
18582 putcombo(buf,0,0,Map.CurrScr()->ffcs[d1].data,Map.CurrScr()->ffcs[d1].cset);
18583 stretch_blit(buf, ffcur, 0,0, 16, 16, 0, 0, ffcur->w, ffcur->h);
18584 destroy_bitmap(buf);
18585 }
18586
18587 object_message(&ffcombo_sel_dlg[5],MSG_DRAW,0);
18588
18589 int32_t xd = x+int32_t(68*1.5);
18590 int32_t y2 = y+int32_t(55*1.5);
18591 int32_t yd = 9;
18592
18593 rectfill(screen,xd,y2,xd+x2+100,y2+yd*14,jwin_pal[jcBOX]);
18594
18595 textprintf_ex(screen,tempfont,xd,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo #:");
18596 textprintf_ex(screen,tempfont,xd+x2,y2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].data);
18597
18598 textprintf_ex(screen,tempfont,xd,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"CSet #:");
18599 textprintf_ex(screen,tempfont,xd+x2,y2+yd,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].cset);
18600
18601 textprintf_ex(screen,tempfont,xd,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Pos:");
18602 textprintf_ex(screen,tempfont,xd+x2,y2+yd*2,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].x.getFloat());
18603
18604 textprintf_ex(screen,tempfont,xd,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Pos:");
18605 textprintf_ex(screen,tempfont,xd+x2,y2+yd*3,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].y.getFloat());
18606
18607 textprintf_ex(screen,tempfont,xd,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Speed:");
18608 textprintf_ex(screen,tempfont,xd+x2,y2+yd*4,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vx.getFloat());
18609
18610 textprintf_ex(screen,tempfont,xd,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Speed:");
18611 textprintf_ex(screen,tempfont,xd+x2,y2+yd*5,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].vy.getFloat());
18612
18613 textprintf_ex(screen,tempfont,xd,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"X Accel:");
18614 textprintf_ex(screen,tempfont,xd+x2,y2+yd*6,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ax.getFloat());
18615
18616 textprintf_ex(screen,tempfont,xd,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Y Accel:");
18617 textprintf_ex(screen,tempfont,xd+x2,y2+yd*7,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%.4f",Map.CurrScr()->ffcs[d1].ay.getFloat());
18618
18619 textprintf_ex(screen,tempfont,xd,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Linked To:");
18620 textprintf_ex(screen,tempfont,xd+x2,y2+yd*8,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].link);
18621
18622 textprintf_ex(screen,tempfont,xd,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Move Delay:");
18623 textprintf_ex(screen,tempfont,xd+x2,y2+yd*9,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",Map.CurrScr()->ffcs[d1].delay);
18624
18625 textprintf_ex(screen,tempfont,xd,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo W:");
18626 textprintf_ex(screen,tempfont,xd+x2,y2+yd*10,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectWidth(d1)));
18627
18628 textprintf_ex(screen,tempfont,xd,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Combo H:");
18629 textprintf_ex(screen,tempfont,xd+x2,y2+yd*11,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffEffectHeight(d1)));
18630
18631 textprintf_ex(screen,tempfont,xd,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile W:");
18632 textprintf_ex(screen,tempfont,xd+x2,y2+yd*12,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileWidth(d1)));
18633
18634 textprintf_ex(screen,tempfont,xd,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"Tile H:");
18635 textprintf_ex(screen,tempfont,xd+x2,y2+yd*13,jwin_pal[jcTEXTFG],jwin_pal[jcBOX],"%d",(Map.CurrScr()->ffTileHeight(d1)));
18636
18637 break;
18638 }
18639
18640 return ret;
18641 }
18642 int32_t onSelectFFCombo()
18643 {
18644 ffcombo_sel_dlg[0].dp2 = get_zc_font(font_lfont);
18645 ffcombo_sel_dlg[3].d1 = ff_combo;
18646 ffcur = create_bitmap_ex(8,32,32);
18647
18648 if(!ffcur) return D_O_K;
18649
18650 Map.CurrScr()->ensureFFC(MAXFFCS - 1);
18651 putcombo(ffcur,0,0,Map.CurrScr()->ffcs[ff_combo].data,Map.CurrScr()->ffcs[ff_combo].cset);
18652 ffcombo_sel_dlg[5].dp = ffcur;
18653
18654 bool resize = !(ffcombo_sel_dlg[0].d1);
18655 large_dialog(ffcombo_sel_dlg);
18656
18657 if(resize)
18658 {
18659 ffcombo_sel_dlg[5].x--;
18660 ffcombo_sel_dlg[5].y--;
18661 }
18662
18663 int32_t ret=do_zqdialog(ffcombo_sel_dlg,0);
18664
18665 while(ret==1)
18666 {
18667 ff_combo = ffcombo_sel_dlg[3].d1;
18668 mapscr* scr = active_visible_screen ? active_visible_screen->scr : Map.CurrScr();
18669 int screen = active_visible_screen ? active_visible_screen->screen : Map.getCurrScr();
18670 call_ffc_dialog(ff_combo, scr, screen);
18671 ret=do_zqdialog(ffcombo_sel_dlg,0);
18672 }
18673
18674 destroy_bitmap(ffcur);
18675 return D_O_K;
18676 }
18677
18678 const char *globalscriptlist(int32_t index, int32_t *list_size);
18679 9 static ListData globalscript_list(globalscriptlist, &font);
18680 const char *playerscriptlist(int32_t index, int32_t *list_size);
18681 9 static ListData playerscript_list(playerscriptlist, &font);
18682
18683 const char *ffscriptlist(int32_t index, int32_t *list_size);
18684
18685 9 static ListData ffscript_list(ffscriptlist, &font);
18686
18687 char *strip_decimals(char *string)
18688 {
18689 int32_t len=(int32_t)strlen(string);
18690 char *src=(char *)malloc(len+1);
18691 char *tmpsrc=src;
18692 memcpy(src,string,len+1);
18693 memset(src,0,len+1);
18694
18695 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18696 {
18697 *tmpsrc=string[i];
18698
18699 if(*tmpsrc=='.')
18700 {
18701 while(string[i+1]=='.'&&i<=strlen(string))
18702 {
18703 i++;
18704 }
18705 }
18706
18707 tmpsrc++;
18708 }
18709
18710 memcpy(string,src,len);
18711 free(src);
18712 return string;
18713 }
18714
18715 // Unused??? -L 6/6/11
18716 char *clean_numeric_string(char *string)
18717 {
18718 bool found_sign=false;
18719 bool found_decimal=false;
18720 int32_t len=(int32_t)strlen(string);
18721 char *src=(char *)malloc(len+1);
18722 char *tmpsrc=src;
18723 memcpy(src,string,len+1);
18724 memset(src,0,len+1);
18725
18726 // strip out non-numerical characters
18727 for(size_t i=0; string[i]&&i<=strlen(string); i++)
18728 {
18729 *tmpsrc=string[i];
18730
18731 if(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18732 {
18733 while(*tmpsrc!='.'&&*tmpsrc!='-'&&*tmpsrc!='+'&&!isdigit(*tmpsrc))
18734 {
18735 i++;
18736 }
18737 }
18738
18739 tmpsrc++;
18740 }
18741
18742 len=(int32_t)strlen(src);
18743 char *src2=(char *)malloc(len+1);
18744 tmpsrc=src2;
18745 memcpy(src,src2,len+1);
18746 memset(src2,0,len+1);
18747
18748 // second purge
18749 for(size_t i=0; src[i]&&i<=strlen(src); i++)
18750 {
18751 *tmpsrc=src[i];
18752
18753 if(*tmpsrc=='-'||*tmpsrc=='+')
18754 {
18755 if(found_sign||found_decimal)
18756 {
18757 while(*tmpsrc=='-'||*tmpsrc=='+')
18758 {
18759 i++;
18760 }
18761 }
18762
18763 found_sign=true;
18764 }
18765
18766 if(*tmpsrc=='.')
18767 {
18768 if(found_decimal)
18769 {
18770 while(*tmpsrc=='.')
18771 {
18772 i++;
18773 }
18774 }
18775
18776 found_decimal=true;
18777 }
18778
18779 tmpsrc++;
18780 }
18781
18782 sprintf(string, "%s", src2);
18783 free(src);
18784 free(src2);
18785 return string;
18786 }
18787
18788 script_struct biglobal[NUMSCRIPTGLOBAL+1]; //global script
18789 int32_t biglobal_cnt = -1;
18790 script_struct biffs[NUMSCRIPTFFC]; //ff script
18791 int32_t biffs_cnt = -1;
18792 script_struct biitems[NUMSCRIPTITEM]; //item script
18793 int32_t biitems_cnt = -1;
18794 script_struct binpcs[NUMSCRIPTGUYS]; //npc script
18795 int32_t binpcs_cnt = -1;
18796
18797 script_struct bilweapons[NUMSCRIPTWEAPONS]; //lweapon script
18798 int32_t bilweapons_cnt = -1;
18799
18800 script_struct bieweapons[NUMSCRIPTWEAPONS]; //eweapon script
18801 int32_t bieweapons_cnt = -1;
18802
18803 script_struct bihero[NUMSCRIPTHERO]; //link script
18804 int32_t bihero_cnt = -1;
18805
18806 script_struct biscreens[NUMSCRIPTSCREEN]; //screen (screendata) script
18807 int32_t biscreens_cnt = -1;
18808
18809 script_struct bidmaps[NUMSCRIPTSDMAP]; //dmap (dmapdata) script
18810 int32_t bidmaps_cnt = -1;
18811
18812 script_struct biditemsprites[NUMSCRIPTSITEMSPRITE]; //dmap (dmapdata) script
18813 int32_t biitemsprites_cnt = -1;
18814
18815 script_struct bidcomboscripts[NUMSCRIPTSCOMBODATA]; //dmap (dmapdata) script
18816 int32_t bidcomboscripts_cnt = -1;
18817 //static char ffscript_str_buf[32];
18818
18819 void build_biglobal_list()
18820 {
18821 biglobal[0].first = "(None)";
18822 biglobal[0].second = -1;
18823 biglobal_cnt = 1;
18824
18825 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; ++i)
18826 {
18827 if(globalmap[i].scriptname.length()==0)
18828 continue;
18829
18830 stringstream ss;
18831 ss << globalmap[i].scriptname << " (" << i << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18832 biglobal[biglobal_cnt].first = ss.str();
18833 biglobal[biglobal_cnt].second = i;
18834 ++biglobal_cnt;
18835 }
18836
18837 // Blank out the rest of the list
18838 for(int32_t i=biglobal_cnt; i<NUMSCRIPTGLOBAL; ++i)
18839 {
18840 biglobal[i].first="";
18841 biglobal[i].second=-1;
18842 }
18843
18844 //Bubble sort! (doesn't account for gaps between scripts)
18845 for(int32_t i = 0; i < biglobal_cnt - 1; i++)
18846 {
18847 for(int32_t j = i + 1; j < biglobal_cnt; j++)
18848 {
18849 if(stricmp(biglobal[i].first.c_str(),biglobal[j].first.c_str()) > 0 && strcmp(biglobal[j].first.c_str(),""))
18850 zc_swap(biglobal[i],biglobal[j]);
18851 }
18852 }
18853
18854 biglobal_cnt = 0;
18855
18856 for(int32_t i = 0; i < NUMSCRIPTGLOBAL+1; ++i)
18857 if(biglobal[i].first.length() > 0)
18858 biglobal_cnt = i+1;
18859 }
18860
18861 4 void build_biffs_list()
18862 {
18863 4 biffs[0].first = "(None)";
18864 4 biffs[0].second = -1;
18865 4 biffs_cnt = 1;
18866
18867
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTFFC - 1; i++)
18868 {
18869
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 1972 times.
2044 if(ffcmap[i].scriptname.length()==0)
18870 1972 continue;
18871
18872 72 stringstream ss;
18873
5/10
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 72 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 72 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 72 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 72 times.
✗ Branch 9 not taken.
72 ss << ffcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18874
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 biffs[biffs_cnt].first = ss.str();
18875 72 biffs[biffs_cnt].second = i;
18876 72 biffs_cnt++;
18877 72 }
18878
18879 // Blank out the rest of the list
18880
2/2
✓ Branch 0 taken 1972 times.
✓ Branch 1 taken 4 times.
1976 for(int32_t i=biffs_cnt; i<NUMSCRIPTFFC; i++)
18881 {
18882 1972 biffs[i].first="";
18883 1972 biffs[i].second=-1;
18884 1972 }
18885
18886 //Bubble sort! (doesn't account for gaps between scripts)
18887
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 4 times.
76 for(int32_t i = 0; i < biffs_cnt - 1; i++)
18888 {
18889
2/2
✓ Branch 0 taken 1305 times.
✓ Branch 1 taken 72 times.
1377 for(int32_t j = i + 1; j < biffs_cnt; j++)
18890 {
18891
3/4
✓ Branch 0 taken 527 times.
✓ Branch 1 taken 778 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 527 times.
1305 if(stricmp(biffs[i].first.c_str(),biffs[j].first.c_str()) > 0 && strcmp(biffs[j].first.c_str(),""))
18892 527 zc_swap(biffs[i],biffs[j]);
18893 1305 }
18894 72 }
18895
18896 4 biffs_cnt = 0;
18897
18898
2/2
✓ Branch 0 taken 2048 times.
✓ Branch 1 taken 4 times.
2052 for(int32_t i = 0; i < NUMSCRIPTFFC; i++)
18899
2/2
✓ Branch 0 taken 1972 times.
✓ Branch 1 taken 76 times.
2124 if(biffs[i].first.length() > 0)
18900 76 biffs_cnt = i+1;
18901 4 }
18902
18903 //npc scripts
18904 void build_binpcs_list()
18905 {
18906 binpcs[0].first = "(None)";
18907 binpcs[0].second = -1;
18908 binpcs_cnt = 1;
18909
18910 for(int32_t i = 0; i < NUMSCRIPTGUYS - 1; i++)
18911 {
18912 if(npcmap[i].scriptname.length()==0)
18913 continue;
18914
18915 stringstream ss;
18916 ss << npcmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18917 binpcs[binpcs_cnt].first = ss.str();
18918 binpcs[binpcs_cnt].second = i;
18919 binpcs_cnt++;
18920 }
18921
18922 // Blank out the rest of the list
18923 for(int32_t i=binpcs_cnt; i<NUMSCRIPTGUYS; i++)
18924 {
18925 binpcs[i].first="";
18926 binpcs[i].second=-1;
18927 }
18928
18929 //Bubble sort! (doesn't account for gaps between scripts)
18930 for(int32_t i = 0; i < binpcs_cnt - 1; i++)
18931 {
18932 for(int32_t j = i + 1; j < binpcs_cnt; j++)
18933 {
18934 if(stricmp(binpcs[i].first.c_str(),binpcs[j].first.c_str()) > 0 && strcmp(binpcs[j].first.c_str(),""))
18935 zc_swap(binpcs[i],binpcs[j]);
18936 }
18937 }
18938
18939 binpcs_cnt = 0;
18940
18941 for(int32_t i = 0; i < NUMSCRIPTGUYS; i++)
18942 if(binpcs[i].first.length() > 0)
18943 binpcs_cnt = i+1;
18944 }
18945
18946
18947 //lweapon scripts
18948 void build_bilweapons_list()
18949 {
18950 bilweapons[0].first = "(None)";
18951 bilweapons[0].second = -1;
18952 bilweapons_cnt = 1;
18953
18954 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
18955 {
18956 if(lwpnmap[i].scriptname.length()==0)
18957 continue;
18958
18959 stringstream ss;
18960 ss << lwpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
18961 bilweapons[bilweapons_cnt].first = ss.str();
18962 bilweapons[bilweapons_cnt].second = i;
18963 bilweapons_cnt++;
18964 }
18965
18966 // Blank out the rest of the list
18967 for(int32_t i=bilweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
18968 {
18969 bilweapons[i].first="";
18970 bilweapons[i].second=-1;
18971 }
18972
18973 //Bubble sort! (doesn't account for gaps between scripts)
18974 for(int32_t i = 0; i < bilweapons_cnt - 1; i++)
18975 {
18976 for(int32_t j = i + 1; j < bilweapons_cnt; j++)
18977 {
18978 if(stricmp(bilweapons[i].first.c_str(),bilweapons[j].first.c_str()) > 0 && strcmp(bilweapons[j].first.c_str(),""))
18979 zc_swap(bilweapons[i],bilweapons[j]);
18980 }
18981 }
18982
18983 bilweapons_cnt = 0;
18984
18985 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
18986 if(bilweapons[i].first.length() > 0)
18987 bilweapons_cnt = i+1;
18988 }
18989
18990 //eweapon scripts
18991 void build_bieweapons_list()
18992 {
18993 bieweapons[0].first = "(None)";
18994 bieweapons[0].second = -1;
18995 bieweapons_cnt = 1;
18996
18997 for(int32_t i = 0; i < NUMSCRIPTWEAPONS - 1; i++)
18998 {
18999 if(ewpnmap[i].scriptname.length()==0)
19000 continue;
19001
19002 stringstream ss;
19003 ss << ewpnmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19004 bieweapons[bieweapons_cnt].first = ss.str();
19005 bieweapons[bieweapons_cnt].second = i;
19006 bieweapons_cnt++;
19007 }
19008
19009 // Blank out the rest of the list
19010 for(int32_t i=bieweapons_cnt; i<NUMSCRIPTWEAPONS; i++)
19011 {
19012 bieweapons[i].first="";
19013 bieweapons[i].second=-1;
19014 }
19015
19016 //Bubble sort! (doesn't account for gaps between scripts)
19017 for(int32_t i = 0; i < bieweapons_cnt - 1; i++)
19018 {
19019 for(int32_t j = i + 1; j < bieweapons_cnt; j++)
19020 {
19021 if(stricmp(bieweapons[i].first.c_str(),bieweapons[j].first.c_str()) > 0 && strcmp(bieweapons[j].first.c_str(),""))
19022 zc_swap(bieweapons[i],bieweapons[j]);
19023 }
19024 }
19025
19026 bieweapons_cnt = 0;
19027
19028 for(int32_t i = 0; i < NUMSCRIPTWEAPONS; i++)
19029 if(bieweapons[i].first.length() > 0)
19030 bieweapons_cnt = i+1;
19031 }
19032
19033 //player scripts
19034 void build_bihero_list()
19035 {
19036 bihero[0].first = "(None)";
19037 bihero[0].second = -1;
19038 bihero_cnt = 1;
19039
19040 for(int32_t i = 0; i < NUMSCRIPTHERO - 1; i++)
19041 {
19042 if(playermap[i].scriptname.length()==0)
19043 continue;
19044
19045 stringstream ss;
19046 ss << playermap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19047 bihero[bihero_cnt].first = ss.str();
19048 bihero[bihero_cnt].second = i;
19049 bihero_cnt++;
19050 }
19051
19052 // Blank out the rest of the list
19053 for(int32_t i=bihero_cnt; i<NUMSCRIPTHERO; i++)
19054 {
19055 bihero[i].first="";
19056 bihero[i].second=-1;
19057 }
19058
19059 //Bubble sort! (doesn't account for gaps between scripts)
19060 for(int32_t i = 0; i < bihero_cnt - 1; i++)
19061 {
19062 for(int32_t j = i + 1; j < bihero_cnt; j++)
19063 {
19064 if(stricmp(bihero[i].first.c_str(),bihero[j].first.c_str()) > 0 && strcmp(bihero[j].first.c_str(),""))
19065 zc_swap(bihero[i],bihero[j]);
19066 }
19067 }
19068
19069 bihero_cnt = 0;
19070
19071 for(int32_t i = 0; i < NUMSCRIPTHERO; i++)
19072 if(bihero[i].first.length() > 0)
19073 bihero_cnt = i+1;
19074 }
19075
19076 //dmap scripts
19077 void build_bidmaps_list()
19078 {
19079 bidmaps[0].first = "(None)";
19080 bidmaps[0].second = -1;
19081 bidmaps_cnt = 1;
19082
19083 for(int32_t i = 0; i < NUMSCRIPTSDMAP - 1; i++)
19084 {
19085 if(dmapmap[i].scriptname.length()==0)
19086 continue;
19087
19088 stringstream ss;
19089 ss << dmapmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19090 bidmaps[bidmaps_cnt].first = ss.str();
19091 bidmaps[bidmaps_cnt].second = i;
19092 bidmaps_cnt++;
19093 }
19094
19095 // Blank out the rest of the list
19096 for(int32_t i=bidmaps_cnt; i<NUMSCRIPTSDMAP; i++)
19097 {
19098 bidmaps[i].first="";
19099 bidmaps[i].second=-1;
19100 }
19101
19102 //Bubble sort! (doesn't account for gaps between scripts)
19103 for(int32_t i = 0; i < bidmaps_cnt - 1; i++)
19104 {
19105 for(int32_t j = i + 1; j < bidmaps_cnt; j++)
19106 {
19107 if(stricmp(bidmaps[i].first.c_str(),bidmaps[j].first.c_str()) > 0 && strcmp(bidmaps[j].first.c_str(),""))
19108 zc_swap(bidmaps[i],bidmaps[j]);
19109 }
19110 }
19111
19112 bidmaps_cnt = 0;
19113
19114 for(int32_t i = 0; i < NUMSCRIPTSDMAP; i++)
19115 if(bidmaps[i].first.length() > 0)
19116 bidmaps_cnt = i+1;
19117 }
19118
19119 //screen scripts
19120 void build_biscreens_list()
19121 {
19122 biscreens[0].first = "(None)";
19123 biscreens[0].second = -1;
19124 biscreens_cnt = 1;
19125
19126 for(int32_t i = 0; i < NUMSCRIPTSCREEN - 1; i++)
19127 {
19128 if(screenmap[i].scriptname.length()==0)
19129 continue;
19130
19131 stringstream ss;
19132 ss << screenmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19133 biscreens[biscreens_cnt].first = ss.str();
19134 biscreens[biscreens_cnt].second = i;
19135 biscreens_cnt++;
19136 }
19137
19138 // Blank out the rest of the list
19139 for(int32_t i=biscreens_cnt; i<NUMSCRIPTSCREEN; i++)
19140 {
19141 biscreens[i].first="";
19142 biscreens[i].second=-1;
19143 }
19144
19145 //Bubble sort! (doesn't account for gaps between scripts)
19146 for(int32_t i = 0; i < biscreens_cnt - 1; i++)
19147 {
19148 for(int32_t j = i + 1; j < biscreens_cnt; j++)
19149 {
19150 if(stricmp(biscreens[i].first.c_str(),biscreens[j].first.c_str()) > 0 && strcmp(biscreens[j].first.c_str(),""))
19151 zc_swap(biscreens[i],biscreens[j]);
19152 }
19153 }
19154
19155 biscreens_cnt = 0;
19156
19157 for(int32_t i = 0; i < NUMSCRIPTSCREEN; i++)
19158 if(biscreens[i].first.length() > 0)
19159 biscreens_cnt = i+1;
19160 }
19161
19162 //screen scripts
19163 void build_biitemsprites_list()
19164 {
19165 biditemsprites[0].first = "(None)";
19166 biditemsprites[0].second = -1;
19167 biitemsprites_cnt = 1;
19168
19169 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE - 1; i++)
19170 {
19171 if(itemspritemap[i].scriptname.length()==0)
19172 continue;
19173
19174 stringstream ss;
19175 ss << itemspritemap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19176 biditemsprites[biitemsprites_cnt].first = ss.str();
19177 biditemsprites[biitemsprites_cnt].second = i;
19178 biitemsprites_cnt++;
19179 }
19180
19181 // Blank out the rest of the list
19182 for(int32_t i=biitemsprites_cnt; i<NUMSCRIPTSITEMSPRITE; i++)
19183 {
19184 biditemsprites[i].first="";
19185 biditemsprites[i].second=-1;
19186 }
19187
19188 //Bubble sort! (doesn't account for gaps between scripts)
19189 for(int32_t i = 0; i < biitemsprites_cnt - 1; i++)
19190 {
19191 for(int32_t j = i + 1; j < biitemsprites_cnt; j++)
19192 {
19193 if(stricmp(biditemsprites[i].first.c_str(),biditemsprites[j].first.c_str()) > 0 && strcmp(biditemsprites[j].first.c_str(),""))
19194 zc_swap(biditemsprites[i],biditemsprites[j]);
19195 }
19196 }
19197
19198 biitemsprites_cnt = 0;
19199
19200 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE; i++)
19201 if(biditemsprites[i].first.length() > 0)
19202 biitemsprites_cnt = i+1;
19203 }
19204
19205 4 void build_biitems_list()
19206 {
19207 4 biitems[0].first = "(None)";
19208 4 biitems[0].second = -1;
19209 4 biitems_cnt = 1;
19210
19211
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTITEM - 1; i++, biitems_cnt++)
19212 {
19213 1020 stringstream ss;
19214
19215
4/6
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1020 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✓ Branch 5 taken 1007 times.
1020 if(!itemmap[i].isEmpty())
19216
5/10
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 13 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 13 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 13 times.
✗ Branch 7 not taken.
✓ Branch 8 taken 13 times.
✗ Branch 9 not taken.
13 ss << itemmap[i].scriptname << " (" << i+1 << ")";
19217
19218
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 biitems[biitems_cnt].first = ss.str();
19219 1020 biitems[biitems_cnt].second = i;
19220 1020 }
19221
19222
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < biitems_cnt - 1; i++)
19223 {
19224
2/2
✓ Branch 0 taken 130560 times.
✓ Branch 1 taken 1020 times.
131580 for(int32_t j = i + 1; j < biitems_cnt; j++)
19225 {
19226
4/4
✓ Branch 0 taken 4250 times.
✓ Branch 1 taken 126310 times.
✓ Branch 2 taken 4247 times.
✓ Branch 3 taken 3 times.
130560 if(stricmp(biitems[i].first.c_str(), biitems[j].first.c_str()) > 0 && strcmp(biitems[j].first.c_str(),""))
19227 3 zc_swap(biitems[i], biitems[j]);
19228 130560 }
19229 1020 }
19230
19231 4 biitems_cnt = 0;
19232
19233
2/2
✓ Branch 0 taken 1024 times.
✓ Branch 1 taken 4 times.
1028 for(int32_t i = 0; i < NUMSCRIPTITEM; i++)
19234
2/2
✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 17 times.
1041 if(biitems[i].first.length() > 0)
19235 17 biitems_cnt = i+1;
19236 4 }
19237
19238
19239 //dmap scripts
19240 void build_bidcomboscripts_list()
19241 {
19242 bidcomboscripts[0].first = "(None)";
19243 bidcomboscripts[0].second = -1;
19244 bidcomboscripts_cnt = 1;
19245
19246 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA - 1; i++)
19247 {
19248 if(comboscriptmap[i].scriptname.length()==0)
19249 continue;
19250
19251 stringstream ss;
19252 ss << comboscriptmap[i].scriptname << " (" << i+1 << ")"; // The word 'slot' preceding all of the numbers is a bit cluttersome. -L.
19253 bidcomboscripts[bidcomboscripts_cnt].first = ss.str();
19254 bidcomboscripts[bidcomboscripts_cnt].second = i;
19255 bidcomboscripts_cnt++;
19256 }
19257
19258 // Blank out the rest of the list
19259 for(int32_t i=bidcomboscripts_cnt; i<NUMSCRIPTSCOMBODATA; i++)
19260 {
19261 bidcomboscripts[i].first="";
19262 bidcomboscripts[i].second=-1;
19263 }
19264
19265 //Bubble sort! (doesn't account for gaps between scripts)
19266 for(int32_t i = 0; i < bidcomboscripts_cnt - 1; i++)
19267 {
19268 for(int32_t j = i + 1; j < bidcomboscripts_cnt; j++)
19269 {
19270 if(stricmp(bidcomboscripts[i].first.c_str(),bidcomboscripts[j].first.c_str()) > 0 && strcmp(bidcomboscripts[j].first.c_str(),""))
19271 zc_swap(bidcomboscripts[i],bidcomboscripts[j]);
19272 }
19273 }
19274
19275 bidcomboscripts_cnt = 0;
19276
19277 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA; i++)
19278 if(bidcomboscripts[i].first.length() > 0)
19279 bidcomboscripts_cnt = i+1;
19280 }
19281
19282
19283 const char *globalscriptlist(int32_t index, int32_t *list_size)
19284 {
19285 if(index < 0)
19286 {
19287 *list_size = biglobal_cnt;
19288 return NULL;
19289 }
19290
19291 return biglobal[index].first.c_str();
19292 }
19293
19294 const char *ffscriptlist(int32_t index, int32_t *list_size)
19295 {
19296 if(index < 0)
19297 {
19298 *list_size = biffs_cnt;
19299 return NULL;
19300 }
19301
19302 return biffs[index].first.c_str();
19303 }
19304
19305 const char *playerscriptlist(int32_t index, int32_t *list_size)
19306 {
19307 if(index < 0)
19308 {
19309 *list_size = bihero_cnt;
19310 return NULL;
19311 }
19312
19313 return bihero[index].first.c_str();
19314 }
19315
19316 const char *lweaponscriptlist(int32_t index, int32_t *list_size)
19317 {
19318 if(index < 0)
19319 {
19320 *list_size = bilweapons_cnt;
19321 return NULL;
19322 }
19323
19324 return bilweapons[index].first.c_str();
19325 }
19326
19327 const char *npcscriptlist(int32_t index, int32_t *list_size)
19328 {
19329 if(index < 0)
19330 {
19331 *list_size = binpcs_cnt;
19332 return NULL;
19333 }
19334
19335 return binpcs[index].first.c_str();
19336 }
19337
19338 static char itemscript_str_buf[32];
19339
19340 char *itemscriptlist(int32_t index, int32_t *list_size)
19341 {
19342 if(index>=0)
19343 {
19344 bound(index,0,255);
19345 sprintf(itemscript_str_buf,"%d: %s",index, ffcmap[index-1].scriptname.c_str());
19346 return itemscript_str_buf;
19347 }
19348
19349 *list_size=256;
19350 return NULL;
19351 }
19352
19353 static char ffscript_str_buf2[32];
19354
19355 const char *ffscriptlist2(int32_t index, int32_t *list_size)
19356 {
19357 if(index>=0)
19358 {
19359 char buf[20];
19360 bound(index,0,510);
19361
19362 if(ffcmap[index].scriptname=="")
19363 strcpy(buf, "<none>");
19364 else
19365 {
19366 strncpy(buf, ffcmap[index].scriptname.c_str(), 19);
19367 buf[19]='\0';
19368 }
19369
19370 sprintf(ffscript_str_buf2,"%d: %s",index+1, buf);
19371 return ffscript_str_buf2;
19372 }
19373
19374 *list_size=511;
19375 return NULL;
19376 }
19377
19378 static char itemscript_str_buf2[32];
19379
19380 const char *itemscriptlist2(int32_t index, int32_t *list_size)
19381 {
19382 if(index>=0)
19383 {
19384 char buf[20];
19385 bound(index,0,254);
19386
19387 if(itemmap[index].scriptname=="")
19388 strcpy(buf, "<none>");
19389 else
19390 {
19391 strncpy(buf, itemmap[index].scriptname.c_str(), 19);
19392 buf[19]='\0';
19393 }
19394
19395 sprintf(itemscript_str_buf2,"%d: %s",index+1, buf);
19396 return itemscript_str_buf2;
19397 }
19398
19399 *list_size=255;
19400 return NULL;
19401 }
19402
19403
19404 static char comboscript_str_buf2[32];
19405 const char *comboscriptlist2(int32_t index, int32_t *list_size)
19406 {
19407 if(index>=0)
19408 {
19409 char buf[20];
19410 bound(index,0,254);
19411
19412 if(comboscriptmap[index].scriptname=="")
19413 strcpy(buf, "<none>");
19414 else
19415 {
19416 strncpy(buf, comboscriptmap[index].scriptname.c_str(), 19);
19417 buf[19]='\0';
19418 }
19419
19420 sprintf(comboscript_str_buf2,"%d: %s",index+1, buf);
19421 return comboscript_str_buf2;
19422 }
19423
19424 *list_size=255;
19425 return NULL;
19426 }
19427
19428 static char gscript_str_buf2[40];
19429
19430 const char *gscriptlist2(int32_t index, int32_t *list_size)
19431 {
19432 if(index >= 0)
19433 {
19434 bound(index,0,3);
19435
19436 char buf[20];
19437
19438 if(globalmap[index].scriptname == "")
19439 strcpy(buf, "<none>");
19440 else
19441 {
19442 strncpy(buf, globalmap[index].scriptname.c_str(), 19);
19443 buf[19]='\0';
19444 }
19445
19446 switch(index)
19447 {
19448 case GLOBAL_SCRIPT_INIT:
19449 sprintf(gscript_str_buf2,"Initialization: %s", buf); break;
19450 case GLOBAL_SCRIPT_GAME:
19451 sprintf(gscript_str_buf2,"Active: %s", buf); break;
19452 case GLOBAL_SCRIPT_END:
19453 sprintf(gscript_str_buf2,"onExit: %s", buf); break;
19454 case GLOBAL_SCRIPT_ONSAVELOAD:
19455 sprintf(gscript_str_buf2,"onSaveLoad: %s", buf); break;
19456 case GLOBAL_SCRIPT_ONLAUNCH:
19457 sprintf(gscript_str_buf2,"onLaunch: %s", buf); break;
19458 case GLOBAL_SCRIPT_ONCONTGAME:
19459 sprintf(gscript_str_buf2,"onContGame: %s", buf); break;
19460 case GLOBAL_SCRIPT_F6:
19461 sprintf(gscript_str_buf2,"onF6Menu: %s", buf); break;
19462 case GLOBAL_SCRIPT_ONSAVE:
19463 sprintf(gscript_str_buf2,"onSave: %s", buf); break;
19464 }
19465
19466 return gscript_str_buf2;
19467 }
19468
19469 if(list_size != NULL)
19470 *list_size=4;
19471
19472 return NULL;
19473 }
19474
19475 static int32_t as_ffc_list[] = { 4, 5, 6, -1};
19476 static int32_t as_global_list[] = { 7, 8, 9, -1}; //Why does putting 15 in here not place my message only on the global tab? ~Joe
19477 static int32_t as_item_list[] = { 10, 11, 12, -1};
19478 static int32_t as_npc_list[] = { 18, 19, 20, -1}; //npc scripts TAB
19479 static int32_t as_lweapon_list[] = { 21, 22, 23, -1}; //lweapon scripts TAB
19480 static int32_t as_eweapon_list[] = { 24, 25, 26, -1}; //eweapon scripts TAB
19481 static int32_t as_hero_list[] = { 27, 28, 29, -1}; //hero scripts TAB
19482 static int32_t as_screen_list[] = { 30, 31, 32, -1}; //screendata scripts TAB
19483 static int32_t as_dmap_list[] = { 33, 34, 35, -1}; //dmapdata scripts TAB
19484 static int32_t as_itemsprite_list[] = { 36, 37, 38, -1}; //dmapdata scripts TAB
19485 static int32_t as_comboscript_list[] = { 39, 40, 41, -1}; //combodata scripts TAB
19486 static int32_t as_genericscript_list[] = { 45, 46, 47, -1}; //generic scripts TAB
19487 static int32_t as_subscreenscript_list[] = { 48, 49, 50, -1}; //generic scripts TAB
19488
19489 static TABPANEL assignscript_tabs[] =
19490 {
19491 // (text)
19492 { (char *)"FFC", D_SELECTED, as_ffc_list, 0, NULL },
19493 { (char *)"Global", 0, as_global_list, 0, NULL },
19494 { (char *)"Item", 0, as_item_list, 0, NULL },
19495 { (char *)"NPC", 0, as_npc_list, 0, NULL },
19496 { (char *)"LWeapon", 0, as_lweapon_list, 0, NULL },
19497 { (char *)"EWeapon", 0, as_eweapon_list, 0, NULL },
19498 { (char *)"Hero", 0, as_hero_list, 0, NULL },
19499 { (char *)"DMap", 0, as_dmap_list, 0, NULL },
19500 { (char *)"Screen", 0, as_screen_list, 0, NULL },
19501 { (char *)"Item Sprite", 0, as_itemsprite_list, 0, NULL },
19502 { (char *)"Combo", 0, as_comboscript_list, 0, NULL },
19503 { (char *)"Generic", 0, as_genericscript_list, 0, NULL },
19504 { (char *)"Subscreen", 0, as_subscreenscript_list, 0, NULL },
19505 { NULL, 0, NULL, 0, NULL }
19506 };
19507
19508 const char *assignffclist(int32_t index, int32_t *list_size)
19509 {
19510 if(index<0)
19511 {
19512 *list_size = (int32_t)ffcmap.size();
19513 return NULL;
19514 }
19515
19516 return ffcmap[index].output.c_str();
19517 }
19518
19519 const char *assigngloballist(int32_t index, int32_t *list_size)
19520 {
19521 if(index<0)
19522 {
19523 *list_size = (int32_t)globalmap.size();
19524 return NULL;
19525 }
19526
19527 return globalmap[index].output.c_str();
19528 }
19529
19530 const char *assigncombolist(int32_t index, int32_t *list_size)
19531 {
19532 if(index<0)
19533 {
19534 *list_size = (int32_t)comboscriptmap.size();
19535 return NULL;
19536 }
19537
19538 return comboscriptmap[index].output.c_str();
19539 }
19540
19541 const char *assigngenericlist(int32_t index, int32_t *list_size)
19542 {
19543 if(index<0)
19544 {
19545 *list_size = ((int32_t)genericmap.size());
19546 return NULL;
19547 }
19548
19549 return genericmap[index].output.c_str();
19550 }
19551
19552 const char *assignsubscreenlist(int32_t index, int32_t *list_size)
19553 {
19554 if(index<0)
19555 {
19556 *list_size = ((int32_t)subscreenmap.size());
19557 return NULL;
19558 }
19559
19560 return subscreenmap[index].output.c_str();
19561 }
19562
19563 const char *assignitemlist(int32_t index, int32_t *list_size)
19564 {
19565 if(index<0)
19566 {
19567 *list_size = (int32_t)itemmap.size();
19568 return NULL;
19569 }
19570
19571 return itemmap[index].output.c_str();
19572 }
19573 const char *assignnpclist(int32_t index, int32_t *list_size)
19574 {
19575 if(index<0)
19576 {
19577 *list_size = (int32_t)npcmap.size();
19578 return NULL;
19579 }
19580
19581 return npcmap[index].output.c_str();
19582 }
19583
19584 const char *assignlweaponlist(int32_t index, int32_t *list_size)
19585 {
19586 if(index<0)
19587 {
19588 *list_size = (int32_t)lwpnmap.size();
19589 return NULL;
19590 }
19591
19592 return lwpnmap[index].output.c_str();
19593 }
19594
19595 const char *assigneweaponlist(int32_t index, int32_t *list_size)
19596 {
19597 if(index<0)
19598 {
19599 *list_size = (int32_t)ewpnmap.size();
19600 return NULL;
19601 }
19602
19603 return ewpnmap[index].output.c_str();
19604 }
19605
19606 const char *assignplayerlist(int32_t index, int32_t *list_size)
19607 {
19608 if(index<0)
19609 {
19610 *list_size = (int32_t)playermap.size();
19611 return NULL;
19612 }
19613
19614 return playermap[index].output.c_str();
19615 }
19616
19617 const char *assigndmaplist(int32_t index, int32_t *list_size)
19618 {
19619 if(index<0)
19620 {
19621 *list_size = (int32_t)dmapmap.size();
19622 return NULL;
19623 }
19624
19625 return dmapmap[index].output.c_str();
19626 }
19627
19628 const char *assignscreenlist(int32_t index, int32_t *list_size)
19629 {
19630 if(index<0)
19631 {
19632 *list_size = (int32_t)screenmap.size();
19633 return NULL;
19634 }
19635
19636 return screenmap[index].output.c_str();
19637 }
19638
19639 const char *assignitemspritelist(int32_t index, int32_t *list_size)
19640 {
19641 if(index<0)
19642 {
19643 *list_size = (int32_t)itemspritemap.size();
19644 return NULL;
19645 }
19646
19647 return itemspritemap[index].output.c_str();
19648 }
19649
19650 const char *assignffcscriptlist(int32_t index, int32_t *list_size)
19651 {
19652 if(index<0)
19653 {
19654 *list_size = (int32_t)asffcscripts.size();
19655 return NULL;
19656 }
19657
19658 return asffcscripts[index].c_str();
19659 }
19660
19661 const char *assignglobalscriptlist(int32_t index, int32_t *list_size)
19662 {
19663 if(index<0)
19664 {
19665 *list_size = (int32_t)asglobalscripts.size();
19666 return NULL;
19667 }
19668
19669 return asglobalscripts[index].c_str();
19670 }
19671
19672 const char *assignitemscriptlist(int32_t index, int32_t *list_size)
19673 {
19674 if(index<0)
19675 {
19676 *list_size = (int32_t)asitemscripts.size();
19677 return NULL;
19678 }
19679
19680 return asitemscripts[index].c_str();
19681 }
19682
19683 const char *assignnpcscriptlist(int32_t index, int32_t *list_size)
19684 {
19685 if(index<0)
19686 {
19687 *list_size = (int32_t)asnpcscripts.size();
19688 return NULL;
19689 }
19690
19691 return asnpcscripts[index].c_str();
19692 }
19693
19694 const char *assignlweaponscriptlist(int32_t index, int32_t *list_size)
19695 {
19696 if(index<0)
19697 {
19698 *list_size = (int32_t)aslweaponscripts.size();
19699 return NULL;
19700 }
19701
19702 return aslweaponscripts[index].c_str();
19703 }
19704
19705 const char *assigneweaponscriptlist(int32_t index, int32_t *list_size)
19706 {
19707 if(index<0)
19708 {
19709 *list_size = (int32_t)aseweaponscripts.size();
19710 return NULL;
19711 }
19712
19713 return aseweaponscripts[index].c_str();
19714 }
19715
19716 const char *assignplayerscriptlist(int32_t index, int32_t *list_size)
19717 {
19718 if(index<0)
19719 {
19720 *list_size = (int32_t)asplayerscripts.size();
19721 return NULL;
19722 }
19723
19724 return asplayerscripts[index].c_str();
19725 }
19726
19727 const char *assigndmapscriptlist(int32_t index, int32_t *list_size)
19728 {
19729 if(index<0)
19730 {
19731 *list_size = (int32_t)asdmapscripts.size();
19732 return NULL;
19733 }
19734
19735 return asdmapscripts[index].c_str();
19736 }
19737
19738 const char *assignscreenscriptlist(int32_t index, int32_t *list_size)
19739 {
19740 if(index<0)
19741 {
19742 *list_size = (int32_t)asscreenscripts.size();
19743 return NULL;
19744 }
19745
19746 return asscreenscripts[index].c_str();
19747 }
19748
19749 const char *assignitemspritescriptlist(int32_t index, int32_t *list_size)
19750 {
19751 if(index<0)
19752 {
19753 *list_size = (int32_t)asitemspritescripts.size();
19754 return NULL;
19755 }
19756
19757 return asitemspritescripts[index].c_str();
19758 }
19759
19760 const char *assigncomboscriptlist(int32_t index, int32_t *list_size)
19761 {
19762 if(index<0)
19763 {
19764 *list_size = (int32_t)ascomboscripts.size();
19765 return NULL;
19766 }
19767
19768 return ascomboscripts[index].c_str();
19769 }
19770
19771 const char *assigngenericscriptlist(int32_t index, int32_t *list_size)
19772 {
19773 if(index<0)
19774 {
19775 *list_size = (int32_t)asgenericscripts.size();
19776 return NULL;
19777 }
19778
19779 return asgenericscripts[index].c_str();
19780 }
19781
19782 const char *assignsubscreenscriptlist(int32_t index, int32_t *list_size)
19783 {
19784 if(index<0)
19785 {
19786 *list_size = (int32_t)assubscreenscripts.size();
19787 return NULL;
19788 }
19789
19790 return assubscreenscripts[index].c_str();
19791 }
19792
19793 9 static ListData assignffc_list(assignffclist, &font);
19794 9 static ListData assignffcscript_list(assignffcscriptlist, &font);
19795 9 static ListData assignglobal_list(assigngloballist, &font);
19796 9 static ListData assignglobalscript_list(assignglobalscriptlist, &font);
19797 9 static ListData assignitem_list(assignitemlist, &font);
19798 9 static ListData assignitemscript_list(assignitemscriptlist, &font);
19799 9 static ListData assignnpc_list(assignnpclist, &font);
19800 9 static ListData assignnpcscript_list(assignnpcscriptlist, &font);
19801 9 static ListData assignlweapon_list(assignlweaponlist, &font);
19802 9 static ListData assignlweaponscript_list(assignlweaponscriptlist, &font);
19803 9 static ListData assigneweapon_list(assigneweaponlist, &font);
19804 9 static ListData assigneweaponscript_list(assigneweaponscriptlist, &font);
19805
19806 9 static ListData assignplayer_list(assignplayerlist, &font);
19807 9 static ListData assignplayerscript_list(assignplayerscriptlist, &font);
19808
19809 9 static ListData assigndmap_list(assigndmaplist, &font);
19810 9 static ListData assigndmapscript_list(assigndmapscriptlist, &font);
19811
19812 9 static ListData assignscreen_list(assignscreenlist, &font);
19813 9 static ListData assignscreenscript_list(assignscreenscriptlist, &font);
19814
19815 9 static ListData assignitemsprite_list(assignitemspritelist, &font);
19816 9 static ListData assignitemspritescript_list(assignitemspritescriptlist, &font);
19817
19818 9 static ListData assigncombo_list(assigncombolist, &font);
19819 9 static ListData assigncomboscript_list(assigncomboscriptlist, &font);
19820
19821 9 static ListData assigngeneric_list(assigngenericlist, &font);
19822 9 static ListData assigngenericscript_list(assigngenericscriptlist, &font);
19823
19824 9 static ListData assignsubscreen_list(assignsubscreenlist, &font);
19825 9 static ListData assignsubscreenscript_list(assignsubscreenscriptlist, &font);
19826
19827 static DIALOG assignscript_dlg[] =
19828 {
19829 // x y w h fg bg key flags d1 d2 dp
19830 9 { jwin_win_proc, 0, 0, 330, 236, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Assign Compiled Script", NULL, NULL },
19831 9 { jwin_tab_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, (void*)assignscript_dlg },
19832 9 { jwin_button_proc, 251, 207, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
19833 9 { jwin_button_proc, 182, 207, 61, 21, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
19834 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffc_list, NULL, NULL },
19835 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignffcscript_list, NULL, NULL },
19836 //6
19837 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19838 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobal_list, NULL, NULL },
19839 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignglobalscript_list, NULL, NULL },
19840 //9
19841 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19842 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitem_list, NULL, NULL },
19843 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemscript_list, NULL, NULL },
19844 //12
19845 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19846 //13
19847 9 { jwin_check_proc, 22, 211, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "Output ZASM code to allegro.log", NULL, NULL },
19848 9 { jwin_text_proc, 22, 178, 90, 24, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19849 9 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19850 //16
19851 9 { d_dummy_proc, 0, 0, 0, 0, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
19852 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
19853 //npc scripts
19854 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpc_list, NULL, NULL },
19855 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignnpcscript_list, NULL, NULL },
19856 //20
19857 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19858 //21
19859 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweapon_list, NULL, NULL },
19860 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignlweaponscript_list, NULL, NULL },
19861 //23
19862 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19863 //24
19864 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweapon_list, NULL, NULL },
19865 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigneweaponscript_list, NULL, NULL },
19866 //26
19867 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19868 //27
19869 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayer_list, NULL, NULL },
19870 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignplayerscript_list, NULL, NULL },
19871 //29
19872 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19873 //30
19874 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreen_list, NULL, NULL },
19875 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignscreenscript_list, NULL, NULL },
19876 //32
19877 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19878 //33
19879 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmap_list, NULL, NULL },
19880 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigndmapscript_list, NULL, NULL },
19881 //35
19882 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19883 //36
19884 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemsprite_list, NULL, NULL },
19885 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignitemspritescript_list, NULL, NULL },
19886 //38
19887 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19888
19889 //39
19890 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncombo_list, NULL, NULL },
19891 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigncomboscript_list, NULL, NULL },
19892 //41
19893 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19894 9 { jwin_button_proc, 78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19895 9 { jwin_button_proc, 174+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Info", NULL, NULL },
19896 9 { jwin_button_proc, 87+78-24, 158, 48, 16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear", NULL, NULL },
19897 //45
19898 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngeneric_list, NULL, NULL },
19899 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assigngenericscript_list, NULL, NULL },
19900 //47
19901 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19902 //48
19903 9 { jwin_abclist_proc, 10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreen_list, NULL, NULL },
19904 9 { jwin_abclist_proc, 174+10, 45, 136, 105, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0,0,0, 0, (void *)&assignsubscreenscript_list, NULL, NULL },
19905 //50
19906 9 { jwin_button_proc, 154+5, 93, 15, 10, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "<<", NULL, NULL },
19907 9 { jwin_check_proc, 22, 221, 90, 8, vc(14), vc(1), 0, 0, 1, 0, (void *) "...And output ZASM comments", NULL, NULL },
19908
19909 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
19910
19911 };
19912
19913 int32_t txtout(BITMAP* dest, const char* txt, int32_t x, int32_t y, bool disabled)
19914 {
19915 if(disabled)
19916 {
19917 gui_textout_ln(dest, font, (uint8_t*)txt, x+1, y+1, scheme[jcLIGHT], scheme[jcBOX], 0);
19918 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcMEDDARK], -1, 0);
19919 }
19920 else
19921 {
19922 return gui_textout_ln(dest, font, (uint8_t*)txt, x, y, scheme[jcBOXFG], scheme[jcBOX], 0);
19923 }
19924 }
19925
19926 int32_t jwin_zmeta_proc(int32_t msg, DIALOG *d, int32_t )
19927 {
19928 int32_t ret = D_O_K;
19929 ASSERT(d);
19930
19931 BITMAP* target = (msg==MSG_START ? NULL : screen);
19932 switch(msg)
19933 {
19934 case MSG_START:
19935 case MSG_DRAW:
19936 {
19937 FONT *oldfont = font;
19938
19939 if(d->dp2)
19940 {
19941 font = (FONT*)d->dp2;
19942 }
19943
19944 bool disabled = (d->flags & D_DISABLED) != 0;
19945 if(d->dp)
19946 {
19947 zasm_meta const& meta = *((zasm_meta*)d->dp);
19948 int32_t ind = -1;
19949 d->w = 0;
19950 if(!meta.valid())
19951 {
19952 d->w = txtout(target, "Invalid ZASM metadata found!", d->x, d->y, disabled);
19953 ++ind;
19954 }
19955
19956 int32_t t_w = 0;
19957 char buf[1024];
19958 memset(buf, 0, sizeof(buf));
19959 sprintf(buf, "ZASM Version: %d", meta.zasm_v);
19960 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19961 d->w = zc_max(d->w, t_w);
19962 memset(buf, 0, sizeof(buf));
19963 sprintf(buf, "Metadata Version: %d", meta.meta_v);
19964 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19965 d->w = zc_max(d->w, t_w);
19966 memset(buf, 0, sizeof(buf));
19967 sprintf(buf, "FFScript Version: %d", meta.ffscript_v);
19968 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19969 d->w = zc_max(d->w, t_w);
19970 memset(buf, 0, sizeof(buf));
19971 sprintf(buf, "Script Name: %s", meta.script_name.c_str());
19972 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19973 d->w = zc_max(d->w, t_w);
19974 memset(buf, 0, sizeof(buf));
19975 sprintf(buf, "Author: %s", meta.author.c_str());
19976 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19977 d->w = zc_max(d->w, t_w);
19978 memset(buf, 0, sizeof(buf));
19979 sprintf(buf, "Script Type: %s", get_script_name(meta.script_type).c_str());
19980 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19981 d->w = zc_max(d->w, t_w);
19982 for(auto q = 0; q < 4; ++q)
19983 {
19984 if(!meta.attributes[q].size())
19985 continue;
19986 memset(buf, 0, sizeof(buf));
19987 sprintf(buf, "Attributes[%d]: %s", q, meta.attributes[q].c_str());
19988 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19989 d->w = zc_max(d->w, t_w);
19990 }
19991 for(auto q = 0; q < 8; ++q)
19992 {
19993 if(!meta.attribytes[q].size())
19994 continue;
19995 memset(buf, 0, sizeof(buf));
19996 sprintf(buf, "Attribytes[%d]: %s", q, meta.attribytes[q].c_str());
19997 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
19998 d->w = zc_max(d->w, t_w);
19999 }
20000 for(auto q = 0; q < 8; ++q)
20001 {
20002 if(!meta.attrishorts[q].size())
20003 continue;
20004 memset(buf, 0, sizeof(buf));
20005 sprintf(buf, "Attrishorts[%d]: %s", q, meta.attrishorts[q].c_str());
20006 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20007 d->w = zc_max(d->w, t_w);
20008 }
20009 bool indentrun = false;
20010 int32_t run_indent = txtout(NULL, "void run(", 0, 0, false);
20011 std::ostringstream oss;
20012 oss << "void run(";
20013 for(int32_t q = 0; q < 8; ++q)
20014 {
20015 if(!meta.run_idens[q].size() || meta.run_types[q] == ZMETA_NULL_TYPE) continue;
20016 if(q > 0)
20017 oss << ", ";
20018 string type_name = ZScript::getDataTypeName(meta.run_types[q]);
20019 lowerstr(type_name); //all lowercase for this output
20020 if(oss.str().size() > unsigned(indentrun ? 41 : 50))
20021 {
20022 memset(buf, 0, sizeof(buf));
20023 sprintf(buf, "%s", oss.str().c_str());
20024 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
20025 d->w = zc_max(d->w, t_w);
20026 oss.str("");
20027 indentrun = true;
20028 }
20029 oss << type_name.c_str() << " " << meta.run_idens[q];
20030 }
20031 oss << ");";
20032 memset(buf, 0, sizeof(buf));
20033 sprintf(buf, "%s", oss.str().c_str());
20034 t_w = txtout(target, buf, d->x + (indentrun ? run_indent : 0), d->y + ((++ind)*(text_height(font) + 3)), disabled) + (indentrun ? run_indent : 0);
20035 d->w = zc_max(d->w, t_w);
20036 memset(buf, 0, sizeof(buf));
20037 sprintf(buf, "Compiler Version: %d.%d.%d.%d", meta.compiler_v1, meta.compiler_v2, meta.compiler_v3, meta.compiler_v4);
20038 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20039 d->w = zc_max(d->w, t_w);
20040 memset(buf, 0, sizeof(buf));
20041 sprintf(buf, "Parser-generated: %s", (meta.flags & ZMETA_AUTOGEN)!=0 ? "TRUE" : "FALSE");
20042 t_w = txtout(target, buf, d->x, d->y + ((++ind)*(text_height(font) + 3)), disabled);
20043 d->w = zc_max(d->w, t_w);
20044 d->h = (++ind) * (text_height(font) + 3) -3;
20045 }
20046 else
20047 {
20048 d->w = txtout(target, "No ZASM metadata found!", d->x, d->y, disabled);
20049 d->h = text_height(font);
20050 }
20051
20052 if(d->dp3) //function trigger
20053 {
20054 typedef void (*funcType)(void);
20055 funcType func=reinterpret_cast<funcType>(d->dp3);
20056 func();
20057 }
20058
20059 font = oldfont;
20060 break;
20061 }
20062 }
20063
20064 return ret;
20065 }
20066
20067 void resize_scriptinfo_dlg();
20068
20069 static DIALOG scriptinfo_dlg[] =
20070 {
20071 // x y w h fg bg key flags d1 d2 dp
20072 { jwin_win_proc, 0, 0, 200, 150, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Script Metadata", NULL, NULL },
20073 { d_dummy_proc, 6, 25, 330-12, 130, 0, 0, 0, 0, 0, 0, assignscript_tabs, NULL, NULL },
20074 { jwin_button_proc, 70, 120, 60, 20, vc(14), vc(1), 'k', D_EXIT, 0, 0, (void *) "Done", NULL, NULL },
20075 { jwin_zmeta_proc, 50, 30, 100, 100, vc(14), vc(1), 0, 0, 0, 0, NULL, NULL, (void*)resize_scriptinfo_dlg },
20076
20077 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
20078 };
20079
20080 void resize_scriptinfo_dlg()
20081 {
20082 DIALOG *meta_proc = &scriptinfo_dlg[3], *window = &scriptinfo_dlg[0], *ok_button = &scriptinfo_dlg[2];
20083 int32_t bmargin = 15, hmargins = 30;
20084 jwin_ulalign_dialog(scriptinfo_dlg);
20085 window->w = hmargins*2 + meta_proc->w;
20086 meta_proc->x = hmargins;
20087 window->h = meta_proc->y + meta_proc->h + ok_button->h + bmargin*2;
20088 ok_button->x = (window->w/2)-(ok_button->w/2);
20089 ok_button->y = meta_proc->y + meta_proc->h + bmargin;
20090 jwin_center_dialog(scriptinfo_dlg);
20091 }
20092
20093 void showScriptInfo(zasm_meta const* meta)
20094 {
20095 scriptinfo_dlg[3].dp = (void*)meta;
20096 scriptinfo_dlg[0].dp2 = get_zc_font(font_lfont);
20097 large_dialog(scriptinfo_dlg);
20098 jwin_zmeta_proc(MSG_START,&scriptinfo_dlg[3],0); //Calculate size before calling dialog
20099 jwin_center_dialog(scriptinfo_dlg);
20100 do_zqdialog(scriptinfo_dlg,2);
20101 }
20102
20103 void write_includepaths();
20104 void call_compile_settings();
20105 int32_t onZScriptCompilerSettings()
20106 {
20107 call_compile_settings();
20108 return D_O_K;
20109 }
20110
20111 void doEditZScript()
20112 {
20113 if(do_box_edit(zScript, "ZScript Buffer", false, false))
20114 saved=false;
20115 }
20116
20117 std::string qst_cfg_header_from_path(std::string path);
20118 extern char *filepath;
20119 string get_box_cfg_hdr(int num)
20120 {
20121 if(num)
20122 return "misc";
20123 return qst_cfg_header_from_path(filepath);
20124 }
20125
20126 //{ Start type-specific import dlgs
20127 9 static ListData ffscript_sel_dlg_list(ffscriptlist2, &font);
20128 9 static ListData itemscript_sel_dlg_list(itemscriptlist2, &font);
20129 9 static ListData comboscript_sel_dlg_list(comboscriptlist2, &font);
20130 9 static ListData gscript_sel_dlg_list(gscriptlist2, &font);
20131 static char npcscript_str_buf2[32];
20132 const char *npcscriptlist2(int32_t index, int32_t *list_size)
20133 {
20134 if(index>=0)
20135 {
20136 char buf[20];
20137 bound(index,0,254);
20138
20139 if(npcmap[index].scriptname=="")
20140 strcpy(buf, "<none>");
20141 else
20142 {
20143 strncpy(buf, npcmap[index].scriptname.c_str(), 19);
20144 buf[19]='\0';
20145 }
20146
20147 sprintf(npcscript_str_buf2,"%d: %s",index+1, buf);
20148 return npcscript_str_buf2;
20149 }
20150
20151 *list_size=(NUMSCRIPTGUYS-1);
20152 return NULL;
20153 }
20154 9 static ListData npcscript_sel_dlg_list(npcscriptlist2, &font);
20155 static char lweaponscript_str_buf2[32];
20156 const char *lweaponscriptlist2(int32_t index, int32_t *list_size)
20157 {
20158 if(index>=0)
20159 {
20160 char buf[20];
20161 bound(index,0,254);
20162
20163 if(lwpnmap[index].scriptname=="")
20164 strcpy(buf, "<none>");
20165 else
20166 {
20167 strncpy(buf, lwpnmap[index].scriptname.c_str(), 19);
20168 buf[19]='\0';
20169 }
20170
20171 sprintf(lweaponscript_str_buf2,"%d: %s",index+1, buf);
20172 return lweaponscript_str_buf2;
20173 }
20174
20175 *list_size=(NUMSCRIPTWEAPONS-1);
20176 return NULL;
20177 }
20178 9 static ListData lweaponscript_sel_dlg_list(lweaponscriptlist2, &font);
20179 static char eweaponscript_str_buf2[32];
20180 const char *eweaponscriptlist2(int32_t index, int32_t *list_size)
20181 {
20182 if(index>=0)
20183 {
20184 char buf[20];
20185 bound(index,0,254);
20186
20187 if(ewpnmap[index].scriptname=="")
20188 strcpy(buf, "<none>");
20189 else
20190 {
20191 strncpy(buf, ewpnmap[index].scriptname.c_str(), 19);
20192 buf[19]='\0';
20193 }
20194
20195 sprintf(eweaponscript_str_buf2,"%d: %s",index+1, buf);
20196 return eweaponscript_str_buf2;
20197 }
20198
20199 *list_size=(NUMSCRIPTWEAPONS-1);
20200 return NULL;
20201 }
20202 9 static ListData eweaponscript_sel_dlg_list(eweaponscriptlist2, &font);
20203 static char playerscript_str_buf2[32];
20204 const char *playerscriptlist2(int32_t index, int32_t *list_size)
20205 {
20206 if(index>=0)
20207 {
20208 char buf[20];
20209 bound(index,0,3);
20210
20211 if(playermap[index].scriptname=="")
20212 strcpy(buf, "<none>");
20213 else
20214 {
20215 strncpy(buf, playermap[index].scriptname.c_str(), 19);
20216 buf[19]='\0';
20217 }
20218
20219 if(index==0)
20220 sprintf(playerscript_str_buf2,"Init: %s", buf);
20221
20222 if(index==1)
20223 sprintf(playerscript_str_buf2,"Active: %s", buf);
20224
20225 if(index==2)
20226 sprintf(playerscript_str_buf2,"Death: %s", buf);
20227
20228
20229 //sprintf(playerscript_str_buf2,"%d: %s",index+1, buf);
20230 return playerscript_str_buf2;
20231 }
20232
20233 *list_size=(NUMSCRIPTHERO-1);
20234 return NULL;
20235 }
20236 static char itemspritescript_str_buf2[32];
20237 const char *itemspritescriptlist2(int32_t index, int32_t *list_size)
20238 {
20239 if(index>=0)
20240 {
20241 char buf[20];
20242 bound(index,0,254);
20243
20244 if(itemspritemap[index].scriptname=="")
20245 strcpy(buf, "<none>");
20246 else
20247 {
20248 strncpy(buf, itemspritemap[index].scriptname.c_str(), 19);
20249 buf[19]='\0';
20250 }
20251
20252 sprintf(itemspritescript_str_buf2,"%d: %s",index+1, buf);
20253 return itemspritescript_str_buf2;
20254 }
20255
20256 *list_size=(NUMSCRIPTSITEMSPRITE-1);
20257 return NULL;
20258 }
20259 9 static ListData playerscript_sel_dlg_list(playerscriptlist2, &font);
20260 static char dmapscript_str_buf2[32];
20261 const char *dmapscriptlist2(int32_t index, int32_t *list_size)
20262 {
20263 if(index>=0)
20264 {
20265 char buf[20];
20266 bound(index,0,254);
20267
20268 if(dmapmap[index].scriptname=="")
20269 strcpy(buf, "<none>");
20270 else
20271 {
20272 strncpy(buf, dmapmap[index].scriptname.c_str(), 19);
20273 buf[19]='\0';
20274 }
20275
20276 sprintf(dmapscript_str_buf2,"%d: %s",index+1, buf);
20277 return dmapscript_str_buf2;
20278 }
20279
20280 *list_size=(NUMSCRIPTSDMAP-1);
20281 return NULL;
20282 }
20283 9 static ListData dmapscript_sel_dlg_list(dmapscriptlist2, &font);
20284 9 static ListData itemspritescript_sel_dlg_list(itemspritescriptlist2, &font);
20285 static char screenscript_str_buf2[32];
20286 const char *screenscriptlist2(int32_t index, int32_t *list_size)
20287 {
20288 if(index>=0)
20289 {
20290 char buf[20];
20291 bound(index,0,254);
20292
20293 if(screenmap[index].scriptname=="")
20294 strcpy(buf, "<none>");
20295 else
20296 {
20297 strncpy(buf, screenmap[index].scriptname.c_str(), 19);
20298 buf[19]='\0';
20299 }
20300
20301 sprintf(screenscript_str_buf2,"%d: %s",index+1, buf);
20302 return screenscript_str_buf2;
20303 }
20304
20305 *list_size=(NUMSCRIPTSCREEN-1);
20306 return NULL;
20307 }
20308 9 static ListData screenscript_sel_dlg_list(screenscriptlist2, &font);
20309 //} End type-specific import dlgs
20310
20311 4 void clear_map_states()
20312 {
20313
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(map<int32_t, script_slot_data>::iterator it = ffcmap.begin();
20314 2048 it != ffcmap.end(); ++it)
20315 {
20316 2044 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20317 2044 }
20318
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
36 for(map<int32_t, script_slot_data>::iterator it = globalmap.begin();
20319 36 it != globalmap.end(); ++it)
20320 {
20321 32 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20322 32 }
20323
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = itemmap.begin();
20324 1024 it != itemmap.end(); ++it)
20325 {
20326 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20327 1020 }
20328
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = npcmap.begin();
20329 1024 it != npcmap.end(); ++it)
20330 {
20331 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20332 1020 }
20333
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = ewpnmap.begin();
20334 1024 it != ewpnmap.end(); ++it)
20335 {
20336 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20337 1020 }
20338
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = lwpnmap.begin();
20339 1024 it != lwpnmap.end(); ++it)
20340 {
20341 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20342 1020 }
20343
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(map<int32_t, script_slot_data>::iterator it = playermap.begin();
20344 20 it != playermap.end(); ++it)
20345 {
20346 16 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20347 16 }
20348
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = dmapmap.begin();
20349 1024 it != dmapmap.end(); ++it)
20350 {
20351 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20352 1020 }
20353
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = screenmap.begin();
20354 1024 it != screenmap.end(); ++it)
20355 {
20356 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20357 1020 }
20358
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(map<int32_t, script_slot_data>::iterator it = itemspritemap.begin();
20359 1024 it != itemspritemap.end(); ++it)
20360 {
20361 1020 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20362 1020 }
20363
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(map<int32_t, script_slot_data>::iterator it = comboscriptmap.begin();
20364 2048 it != comboscriptmap.end(); ++it)
20365 {
20366 2044 (*it).second.format = SCRIPT_FORMAT_DEFAULT;
20367 2044 }
20368 4 }
20369
20370 4 void clearAssignSlotDlg()
20371 {
20372 4 assignscript_dlg[0].dp2 = get_zc_font(font_lfont);
20373 4 assignscript_dlg[4].d1 = -1;
20374 4 assignscript_dlg[5].d1 = -1;
20375 4 assignscript_dlg[7].d1 = -1;
20376 4 assignscript_dlg[8].d1 = -1;
20377 4 assignscript_dlg[10].d1 = -1;
20378 4 assignscript_dlg[11].d1 = -1;
20379 4 assignscript_dlg[13].flags = 0;
20380 4 }
20381
20382 int32_t onSlotAssign()
20383 {
20384 clearAssignSlotDlg();
20385 //Clear right-hand side of names
20386 asffcscripts.clear();
20387 asffcscripts.push_back("<none>");
20388 asglobalscripts.clear();
20389 asglobalscripts.push_back("<none>");
20390 asitemscripts.clear();
20391 asitemscripts.push_back("<none>");
20392 asnpcscripts.clear();
20393 asnpcscripts.push_back("<none>");
20394 aseweaponscripts.clear();
20395 aseweaponscripts.push_back("<none>");
20396 aslweaponscripts.clear();
20397 aslweaponscripts.push_back("<none>");
20398 asplayerscripts.clear();
20399 asplayerscripts.push_back("<none>");
20400 asdmapscripts.clear();
20401 asdmapscripts.push_back("<none>");
20402 asscreenscripts.clear();
20403 asscreenscripts.push_back("<none>");
20404 asitemspritescripts.clear();
20405 asitemspritescripts.push_back("<none>");
20406
20407 ascomboscripts.clear();
20408 ascomboscripts.push_back("<none>");
20409 asgenericscripts.clear();
20410 asgenericscripts.push_back("<none>");
20411 assubscreenscripts.clear();
20412 assubscreenscripts.push_back("<none>");
20413 //Declare new script vector
20414 map<string, disassembled_script_data> scripts;
20415
20416 do_script_disassembly(scripts, false);
20417
20418 do_slots(scripts, false);
20419 return D_O_K;
20420 }
20421
20422 void inc_script_name(string& name)
20423 {
20424 size_t pos = name.find_last_not_of("0123456789");
20425 pos = name.find_first_of("0123456789",pos);
20426 std::ostringstream oss;
20427 if(pos == string::npos)
20428 {
20429 oss << name << 2;
20430 }
20431 else
20432 {
20433 int32_t val = atoi(name.substr(pos).c_str());
20434 oss << name.substr(0,pos) << val+1;
20435 }
20436 name = oss.str();
20437 }
20438
20439 4 void do_script_disassembly(map<string, disassembled_script_data>& scripts, bool fromCompile)
20440 {
20441 4 clearAssignSlotDlg();
20442
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 bool skipDisassembled = fromCompile && try_recovering_missing_scripts == 0;
20443
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
36 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; ++i)
20444 {
20445
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 if(scripts.find(globalmap[i].scriptname) != scripts.end())
20446 {
20447
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(scripts[globalmap[i].scriptname].first.script_type != ScriptType::Global)
20448 {
20449 while(scripts.find(globalmap[i].scriptname) != scripts.end())
20450 inc_script_name(globalmap[i].scriptname);
20451 }
20452 8 else continue;
20453 }
20454
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 switch(i)
20455 {
20456 case GLOBAL_SCRIPT_INIT:
20457 {
20458 break;
20459 }
20460 default:
20461
1/2
✓ Branch 0 taken 24 times.
✗ Branch 1 not taken.
24 if(!globalmap[i].isEmpty())
20462 {
20463 globalmap[i].format = SCRIPT_FORMAT_INVALID;
20464 }
20465 24 }
20466 24 }
20467
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTFFC-1; ++i)
20468 {
20469
2/2
✓ Branch 0 taken 1976 times.
✓ Branch 1 taken 68 times.
2044 if(scripts.find(ffcmap[i].scriptname) != scripts.end())
20470 {
20471
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 68 times.
68 if(scripts[ffcmap[i].scriptname].first.script_type != ScriptType::FFC)
20472 {
20473 while(scripts.find(ffcmap[i].scriptname) != scripts.end())
20474 inc_script_name(ffcmap[i].scriptname);
20475 }
20476 68 else continue;
20477 }
20478
2/2
✓ Branch 0 taken 1972 times.
✓ Branch 1 taken 4 times.
1976 if(!ffcmap[i].isEmpty())
20479 {
20480 4 ffcmap[i].format = SCRIPT_FORMAT_INVALID;
20481 4 }
20482 1976 }
20483
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTITEM-1; ++i)
20484 {
20485
2/2
✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 13 times.
1020 if(scripts.find(itemmap[i].scriptname) != scripts.end())
20486 {
20487
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if(scripts[itemmap[i].scriptname].first.script_type != ScriptType::Item)
20488 {
20489 while(scripts.find(itemmap[i].scriptname) != scripts.end())
20490 inc_script_name(itemmap[i].scriptname);
20491 }
20492 13 else continue;
20493 }
20494
1/2
✓ Branch 0 taken 1007 times.
✗ Branch 1 not taken.
1007 if(!itemmap[i].isEmpty())
20495 {
20496 itemmap[i].format = SCRIPT_FORMAT_INVALID;
20497 }
20498 1007 }
20499
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTGUYS-1; ++i)
20500 {
20501
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(scripts.find(npcmap[i].scriptname) != scripts.end())
20502 {
20503 if(scripts[npcmap[i].scriptname].first.script_type != ScriptType::NPC)
20504 {
20505 while(scripts.find(npcmap[i].scriptname) != scripts.end())
20506 inc_script_name(npcmap[i].scriptname);
20507 }
20508 else continue;
20509 }
20510
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(!npcmap[i].isEmpty())
20511 {
20512 npcmap[i].format = SCRIPT_FORMAT_INVALID;
20513 }
20514 1020 }
20515
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; ++i)
20516 {
20517
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(scripts.find(lwpnmap[i].scriptname) != scripts.end())
20518 {
20519 if(scripts[lwpnmap[i].scriptname].first.script_type != ScriptType::Lwpn)
20520 {
20521 while(scripts.find(lwpnmap[i].scriptname) != scripts.end())
20522 inc_script_name(lwpnmap[i].scriptname);
20523 }
20524 else continue;
20525 }
20526
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(!lwpnmap[i].isEmpty())
20527 {
20528 lwpnmap[i].format = SCRIPT_FORMAT_INVALID;
20529 }
20530 1020 }
20531
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; ++i)
20532 {
20533
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(scripts.find(ewpnmap[i].scriptname) != scripts.end())
20534 {
20535 if(scripts[ewpnmap[i].scriptname].first.script_type != ScriptType::Ewpn)
20536 {
20537 while(scripts.find(ewpnmap[i].scriptname) != scripts.end())
20538 inc_script_name(ewpnmap[i].scriptname);
20539 }
20540 else continue;
20541 }
20542
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(!ewpnmap[i].isEmpty())
20543 {
20544 ewpnmap[i].format = SCRIPT_FORMAT_INVALID;
20545 }
20546 1020 }
20547
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t i = 0; i < NUMSCRIPTHERO-1; ++i)
20548 {
20549
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(scripts.find(playermap[i].scriptname) != scripts.end())
20550 {
20551 if(scripts[playermap[i].scriptname].first.script_type != ScriptType::Hero)
20552 {
20553 while(scripts.find(playermap[i].scriptname) != scripts.end())
20554 inc_script_name(playermap[i].scriptname);
20555 }
20556 else continue;
20557 }
20558
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!playermap[i].isEmpty())
20559 {
20560 playermap[i].format = SCRIPT_FORMAT_INVALID;
20561 }
20562 16 }
20563
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSDMAP-1; ++i)
20564 {
20565
2/2
✓ Branch 0 taken 1018 times.
✓ Branch 1 taken 2 times.
1020 if(scripts.find(dmapmap[i].scriptname) != scripts.end())
20566 {
20567
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(scripts[dmapmap[i].scriptname].first.script_type != ScriptType::DMap)
20568 {
20569 while(scripts.find(dmapmap[i].scriptname) != scripts.end())
20570 inc_script_name(dmapmap[i].scriptname);
20571 }
20572 2 else continue;
20573 }
20574
1/2
✓ Branch 0 taken 1018 times.
✗ Branch 1 not taken.
1018 if(!dmapmap[i].isEmpty())
20575 {
20576 dmapmap[i].format = SCRIPT_FORMAT_INVALID;
20577 }
20578 1018 }
20579
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSCREEN-1; ++i)
20580 {
20581
2/2
✓ Branch 0 taken 1018 times.
✓ Branch 1 taken 2 times.
1020 if(scripts.find(screenmap[i].scriptname) != scripts.end())
20582 {
20583
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(scripts[screenmap[i].scriptname].first.script_type != ScriptType::Screen)
20584 {
20585 while(scripts.find(screenmap[i].scriptname) != scripts.end())
20586 inc_script_name(screenmap[i].scriptname);
20587 }
20588 2 else continue;
20589 }
20590
1/2
✓ Branch 0 taken 1018 times.
✗ Branch 1 not taken.
1018 if(!screenmap[i].isEmpty())
20591 {
20592 screenmap[i].format = SCRIPT_FORMAT_INVALID;
20593 }
20594 1018 }
20595
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE-1; ++i)
20596 {
20597
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(scripts.find(itemspritemap[i].scriptname) != scripts.end())
20598 {
20599 if(scripts[itemspritemap[i].scriptname].first.script_type != ScriptType::ItemSprite)
20600 {
20601 while(scripts.find(itemspritemap[i].scriptname) != scripts.end())
20602 inc_script_name(itemspritemap[i].scriptname);
20603 }
20604 else continue;
20605 }
20606
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(!itemspritemap[i].isEmpty())
20607 {
20608 itemspritemap[i].format = SCRIPT_FORMAT_INVALID;
20609 }
20610 1020 }
20611
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA-1; ++i)
20612 {
20613
1/2
✓ Branch 0 taken 2044 times.
✗ Branch 1 not taken.
2044 if(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
20614 {
20615 if(scripts[comboscriptmap[i].scriptname].first.script_type != ScriptType::Combo)
20616 {
20617 while(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
20618 inc_script_name(comboscriptmap[i].scriptname);
20619 }
20620 else continue;
20621 }
20622
1/2
✓ Branch 0 taken 2044 times.
✗ Branch 1 not taken.
2044 if(!comboscriptmap[i].isEmpty())
20623 {
20624 comboscriptmap[i].format = SCRIPT_FORMAT_INVALID;
20625 }
20626 2044 }
20627
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTSGENERIC-1; ++i)
20628 {
20629
2/2
✓ Branch 0 taken 2039 times.
✓ Branch 1 taken 5 times.
2044 if(scripts.find(genericmap[i].scriptname) != scripts.end())
20630 {
20631
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if(scripts[genericmap[i].scriptname].first.script_type != ScriptType::Generic)
20632 {
20633 while(scripts.find(genericmap[i].scriptname) != scripts.end())
20634 inc_script_name(genericmap[i].scriptname);
20635 }
20636 5 else continue;
20637 }
20638
1/2
✓ Branch 0 taken 2039 times.
✗ Branch 1 not taken.
2039 if(!genericmap[i].isEmpty())
20639 {
20640 genericmap[i].format = SCRIPT_FORMAT_INVALID;
20641 }
20642 2039 }
20643
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 1020 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSSUBSCREEN-1; ++i)
20644 {
20645
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(scripts.find(subscreenmap[i].scriptname) != scripts.end())
20646 {
20647 if(scripts[subscreenmap[i].scriptname].first.script_type != ScriptType::EngineSubscreen)
20648 {
20649 while(scripts.find(subscreenmap[i].scriptname) != scripts.end())
20650 inc_script_name(subscreenmap[i].scriptname);
20651 }
20652 else continue;
20653 }
20654
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(!subscreenmap[i].isEmpty())
20655 {
20656 subscreenmap[i].format = SCRIPT_FORMAT_INVALID;
20657 }
20658 1020 }
20659 4 }
20660
20661 enum script_slot_type
20662 {
20663 type_ffc, type_global, type_itemdata, type_npc, type_lweapon, type_eweapon,
20664 type_hero, type_dmap, type_screen, type_itemsprite, type_combo, type_generic,
20665 type_subscreen, num_types
20666 };
20667 script_slot_type getType(ScriptType type)
20668 {
20669 switch(type)
20670 {
20671 case ScriptType::FFC: return type_ffc;
20672 case ScriptType::Global: return type_global;
20673 case ScriptType::Item: return type_itemdata;
20674 case ScriptType::NPC: return type_npc;
20675 case ScriptType::Lwpn: return type_lweapon;
20676 case ScriptType::Ewpn: return type_eweapon;
20677 case ScriptType::Hero: return type_hero;
20678 case ScriptType::DMap:
20679 case ScriptType::ScriptedActiveSubscreen:
20680 case ScriptType::ScriptedPassiveSubscreen:
20681 case ScriptType::OnMap:
20682 return type_dmap;
20683 case ScriptType::Generic: case ScriptType::GenericFrozen:
20684 return type_generic;
20685 case ScriptType::Screen: return type_screen;
20686 case ScriptType::ItemSprite: return type_itemsprite;
20687 case ScriptType::Combo: return type_combo;
20688 case ScriptType::EngineSubscreen: return type_subscreen;
20689 default: return type_ffc; //Default
20690 }
20691 }
20692 #define SLOTMSGFLAG_MISSING 0x01
20693 #define SLOTMSGFLAG_PRESERVED 0x02
20694 #define SLOTMSGFLAG_IMPORTED 0x04
20695 #define SLOTMSG_SIZE 512
20696 bool checkSkip(int32_t format, byte flags)
20697 {
20698 switch(format)
20699 {
20700 case SCRIPT_FORMAT_DEFAULT:
20701 return (flags != 0);
20702 case SCRIPT_FORMAT_INVALID:
20703 return ((flags & SLOTMSGFLAG_MISSING)==0);
20704 case SCRIPT_FORMAT_DISASSEMBLED:
20705 return ((flags & SLOTMSGFLAG_PRESERVED)==0);
20706 case SCRIPT_FORMAT_ZASM:
20707 return ((flags & SLOTMSGFLAG_IMPORTED)==0);
20708 default: return true;
20709 }
20710 }
20711 void clearAllSlots(int32_t type, byte flags = 0)
20712 {
20713 bound(type,0,num_types-1);
20714 switch(type)
20715 {
20716 case type_ffc:
20717 {
20718 for(int32_t q = 0; q < NUMSCRIPTFFC-1; ++q)
20719 {
20720 if(checkSkip(ffcmap[q].format, flags)) continue;
20721 ffcmap[q].scriptname = "";
20722 ffcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20723 }
20724 break;
20725 }
20726 case type_global:
20727 {
20728 //Start at 1 to not clear Init
20729 for(int32_t q = 1; q < NUMSCRIPTGLOBAL; ++q)
20730 {
20731 if(checkSkip(globalmap[q].format, flags)) continue;
20732 globalmap[q].scriptname = "";
20733 globalmap[q].format = SCRIPT_FORMAT_DEFAULT;
20734 }
20735 break;
20736 }
20737 case type_itemdata:
20738 {
20739 for(int32_t q = 0; q < NUMSCRIPTITEM-1; ++q)
20740 {
20741 if(checkSkip(itemmap[q].format, flags)) continue;
20742 itemmap[q].scriptname = "";
20743 itemmap[q].format = SCRIPT_FORMAT_DEFAULT;
20744 }
20745 break;
20746 }
20747 case type_npc:
20748 {
20749 for(int32_t q = 0; q < NUMSCRIPTGUYS-1; ++q)
20750 {
20751 if(checkSkip(npcmap[q].format, flags)) continue;
20752 npcmap[q].scriptname = "";
20753 npcmap[q].format = SCRIPT_FORMAT_DEFAULT;
20754 }
20755 break;
20756 }
20757 case type_lweapon:
20758 {
20759 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20760 {
20761 if(checkSkip(lwpnmap[q].format, flags)) continue;
20762 lwpnmap[q].scriptname = "";
20763 lwpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20764 }
20765 break;
20766 }
20767 case type_eweapon:
20768 {
20769 for(int32_t q = 0; q < NUMSCRIPTWEAPONS-1; ++q)
20770 {
20771 if(checkSkip(ewpnmap[q].format, flags)) continue;
20772 ewpnmap[q].scriptname = "";
20773 ewpnmap[q].format = SCRIPT_FORMAT_DEFAULT;
20774 }
20775 break;
20776 }
20777 case type_hero:
20778 {
20779 for(int32_t q = 0; q < NUMSCRIPTHERO-1; ++q)
20780 {
20781 if(checkSkip(playermap[q].format, flags)) continue;
20782 playermap[q].scriptname = "";
20783 playermap[q].format = SCRIPT_FORMAT_DEFAULT;
20784 }
20785 break;
20786 }
20787 case type_dmap:
20788 {
20789 for(int32_t q = 0; q < NUMSCRIPTSDMAP-1; ++q)
20790 {
20791 if(checkSkip(dmapmap[q].format, flags)) continue;
20792 dmapmap[q].scriptname = "";
20793 dmapmap[q].format = SCRIPT_FORMAT_DEFAULT;
20794 }
20795 break;
20796 }
20797 case type_screen:
20798 {
20799 for(int32_t q = 0; q < NUMSCRIPTSCREEN-1; ++q)
20800 {
20801 if(checkSkip(screenmap[q].format, flags)) continue;
20802 screenmap[q].scriptname = "";
20803 screenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20804 }
20805 break;
20806 }
20807 case type_itemsprite:
20808 {
20809 for(int32_t q = 0; q < NUMSCRIPTSITEMSPRITE-1; ++q)
20810 {
20811 if(checkSkip(itemspritemap[q].format, flags)) continue;
20812 itemspritemap[q].scriptname = "";
20813 itemspritemap[q].format = SCRIPT_FORMAT_DEFAULT;
20814 }
20815 break;
20816 }
20817 case type_combo:
20818 {
20819 for(int32_t q = 0; q < NUMSCRIPTSCOMBODATA-1; ++q)
20820 {
20821 if(checkSkip(comboscriptmap[q].format, flags)) continue;
20822 comboscriptmap[q].scriptname = "";
20823 comboscriptmap[q].format = SCRIPT_FORMAT_DEFAULT;
20824 }
20825 break;
20826 }
20827 case type_generic:
20828 {
20829 for(int32_t q = 0; q < NUMSCRIPTSGENERIC-1; ++q)
20830 {
20831 if(checkSkip(genericmap[q].format, flags)) continue;
20832 genericmap[q].scriptname = "";
20833 genericmap[q].format = SCRIPT_FORMAT_DEFAULT;
20834 }
20835 break;
20836 }
20837 case type_subscreen:
20838 {
20839 for(int32_t q = 0; q < NUMSCRIPTSSUBSCREEN-1; ++q)
20840 {
20841 if(checkSkip(subscreenmap[q].format, flags)) continue;
20842 subscreenmap[q].scriptname = "";
20843 subscreenmap[q].format = SCRIPT_FORMAT_DEFAULT;
20844 }
20845 break;
20846 }
20847 }
20848 }
20849
20850 static bool doslots_log_output = false, doslots_comment_output = true;
20851 4 void setup_scriptslot_dlg(char* buf, byte flags)
20852 {
20853 //{ Set up the textbox at the bottom, and auto-resize height based on it
20854 4 int32_t prev_height = assignscript_dlg[14].h;
20855 4 memset(buf, 0, SLOTMSG_SIZE);
20856 //
20857 4 strcpy(buf, "Slots with matching names have been updated.\n");
20858
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 2 times.
4 if(flags & SLOTMSGFLAG_MISSING)
20859 2 strcat(buf,"Scripts prefixed with '--' were not found, and will not function.\n");
20860
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(flags & SLOTMSGFLAG_PRESERVED)
20861 strcat(buf, "Scripts prefixed with '++' were not found, but have been preserved.\n"
20862 " These scripts may not function correctly if they use global variables.\n");
20863
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(flags & SLOTMSGFLAG_IMPORTED)
20864 strcat(buf,"Scripts prefixed with '==' are imported ZASM scripts.\n");
20865 4 strcat(buf,"Global scripts named 'Init' will be appended to '~Init'");
20866 //
20867
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 SETFLAG(assignscript_dlg[13].flags, D_SELECTED, doslots_log_output);
20868
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 SETFLAG(assignscript_dlg[51].flags, D_SELECTED, doslots_comment_output);
20869 4 assignscript_dlg[14].dp = buf;
20870 4 object_message(&assignscript_dlg[14], MSG_START, 0); //Set the width/height
20871
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(int32_t diff = assignscript_dlg[14].h - prev_height) //resize dlg
20872 {
20873 4 int32_t prev_bottom = assignscript_dlg[14].y + prev_height;
20874
2/2
✓ Branch 0 taken 204 times.
✓ Branch 1 taken 4 times.
208 for(int32_t q = 1; assignscript_dlg[q].proc; ++q)
20875 {
20876
2/2
✓ Branch 0 taken 4 times.
✓ Branch 1 taken 200 times.
204 if(q==14) continue; //Don't change self
20877
2/2
✓ Branch 0 taken 184 times.
✓ Branch 1 taken 16 times.
200 if(assignscript_dlg[q].y < prev_bottom) continue; //above proc
20878 16 assignscript_dlg[q].y += diff;
20879 16 }
20880 4 assignscript_dlg[0].h += diff;
20881 4 jwin_center_dialog(assignscript_dlg);
20882 4 }
20883 //}
20884 4 }
20885
20886 std::string global_slotnames[NUMSCRIPTGLOBAL] = {
20887 "Init",
20888 "Active",
20889 "onExit",
20890 "onSaveLoad",
20891 "onLaunch",
20892 "onContGame",
20893 "onF6Menu",
20894 "onSave",
20895 };
20896 std::string player_slotnames[NUMSCRIPTHERO-1] = {
20897 "Init",
20898 "Active",
20899 "onDeath",
20900 "onWin",
20901 };
20902 4 byte reload_scripts(map<string, disassembled_script_data> &scripts)
20903 {
20904 4 byte slotflags = 0;
20905 char temp[100];
20906
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTFFC-1; i++)
20907 {
20908
2/2
✓ Branch 0 taken 1972 times.
✓ Branch 1 taken 72 times.
2044 if(ffcmap[i].isEmpty())
20909 1972 sprintf(temp, "Slot %d:", i+1);
20910 else
20911 {
20912 72 sprintf(temp, "Slot %d:", i+1);
20913
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 if(ffcmap[i].isZASM())
20914 {
20915 if(ffcmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
20916 else slotflags |= SLOTMSGFLAG_PRESERVED;
20917 }
20918
2/2
✓ Branch 0 taken 68 times.
✓ Branch 1 taken 4 times.
72 else if(scripts.find(ffcmap[i].scriptname) != scripts.end())
20919 68 ffcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20920 else // Previously loaded script not found
20921 {
20922 4 ffcmap[i].format = SCRIPT_FORMAT_INVALID;
20923 4 slotflags |= SLOTMSGFLAG_MISSING;
20924 }
20925 }
20926 2044 ffcmap[i].slotname = temp;
20927 2044 ffcmap[i].update();
20928 2044 }
20929
2/2
✓ Branch 0 taken 32 times.
✓ Branch 1 taken 4 times.
36 for(int32_t i = 0; i < NUMSCRIPTGLOBAL; i++)
20930 {
20931
1/2
✓ Branch 0 taken 32 times.
✗ Branch 1 not taken.
32 globalmap[i].slotname=fmt::format("{}:",global_slotnames[i]);
20932
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 8 times.
32 if(!globalmap[i].isEmpty())
20933 {
20934
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 8 times.
8 if(globalmap[i].isZASM())
20935 {
20936 if(globalmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
20937 else slotflags |= SLOTMSGFLAG_PRESERVED;
20938 }
20939
2/4
✓ Branch 0 taken 8 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 8 times.
✗ Branch 3 not taken.
8 else if(scripts.find(globalmap[i].scriptname) != scripts.end() || globalmap[i].scriptname == "~Init")
20940 8 globalmap[i].format = SCRIPT_FORMAT_DEFAULT;
20941 else // Unloaded
20942 {
20943 globalmap[i].format = SCRIPT_FORMAT_INVALID;
20944 slotflags |= SLOTMSGFLAG_MISSING;
20945 }
20946 8 }
20947 32 globalmap[i].update();
20948 32 }
20949
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTITEM-1; i++)
20950 {
20951
2/2
✓ Branch 0 taken 1007 times.
✓ Branch 1 taken 13 times.
1020 if(itemmap[i].isEmpty())
20952 1007 sprintf(temp, "Slot %d:", i+1);
20953 else
20954 {
20955 13 sprintf(temp, "Slot %d:", i+1);
20956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 13 times.
13 if(itemmap[i].isZASM())
20957 {
20958 if(itemmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
20959 else slotflags |= SLOTMSGFLAG_PRESERVED;
20960 }
20961
1/2
✓ Branch 0 taken 13 times.
✗ Branch 1 not taken.
13 else if(scripts.find(itemmap[i].scriptname) != scripts.end())
20962 13 itemmap[i].format = SCRIPT_FORMAT_DEFAULT;
20963 else // Previously loaded script not found
20964 {
20965 itemmap[i].format = SCRIPT_FORMAT_INVALID;
20966 slotflags |= SLOTMSGFLAG_MISSING;
20967 }
20968 }
20969 1020 itemmap[i].slotname = temp;
20970 1020 itemmap[i].update();
20971 1020 }
20972
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTGUYS-1; i++)
20973 {
20974
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(npcmap[i].isEmpty())
20975 1020 sprintf(temp, "Slot %d:", i+1);
20976 else
20977 {
20978 sprintf(temp, "Slot %d:", i+1);
20979 if(npcmap[i].isZASM())
20980 {
20981 if(npcmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
20982 else slotflags |= SLOTMSGFLAG_PRESERVED;
20983 }
20984 else if(scripts.find(npcmap[i].scriptname) != scripts.end())
20985 npcmap[i].format = SCRIPT_FORMAT_DEFAULT;
20986 else // Previously loaded script not found
20987 {
20988 npcmap[i].format = SCRIPT_FORMAT_INVALID;
20989 slotflags |= SLOTMSGFLAG_MISSING;
20990 }
20991 }
20992 1020 npcmap[i].slotname = temp;
20993 1020 npcmap[i].update();
20994 1020 }
20995
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
20996 {
20997
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(ewpnmap[i].isEmpty())
20998 1020 sprintf(temp, "Slot %d:", i+1);
20999 else
21000 {
21001 sprintf(temp, "Slot %d:", i+1);
21002 if(ewpnmap[i].isZASM())
21003 {
21004 if(ewpnmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21005 else slotflags |= SLOTMSGFLAG_PRESERVED;
21006 }
21007 else if(scripts.find(ewpnmap[i].scriptname) != scripts.end())
21008 ewpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
21009 else // Previously loaded script not found
21010 {
21011 ewpnmap[i].format = SCRIPT_FORMAT_INVALID;
21012 slotflags |= SLOTMSGFLAG_MISSING;
21013 }
21014 }
21015 1020 ewpnmap[i].slotname = temp;
21016 1020 ewpnmap[i].update();
21017 1020 }
21018
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTWEAPONS-1; i++)
21019 {
21020
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(lwpnmap[i].isEmpty())
21021 1020 sprintf(temp, "Slot %d:", i+1);
21022 else
21023 {
21024 sprintf(temp, "Slot %d:", i+1);
21025 if(lwpnmap[i].isZASM())
21026 {
21027 if(lwpnmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21028 else slotflags |= SLOTMSGFLAG_PRESERVED;
21029 }
21030 else if(scripts.find(lwpnmap[i].scriptname) != scripts.end())
21031 lwpnmap[i].format = SCRIPT_FORMAT_DEFAULT;
21032 else // Previously loaded script not found
21033 {
21034 lwpnmap[i].format = SCRIPT_FORMAT_INVALID;
21035 slotflags |= SLOTMSGFLAG_MISSING;
21036 }
21037 }
21038 1020 lwpnmap[i].slotname = temp;
21039 1020 lwpnmap[i].update();
21040 1020 }
21041
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4 times.
20 for(int32_t i = 0; i < NUMSCRIPTHERO-1; i++)
21042 {
21043
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 playermap[i].slotname=fmt::format("{}:",player_slotnames[i]);
21044
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(!playermap[i].isEmpty())
21045 {
21046 if(playermap[i].isZASM())
21047 {
21048 if(playermap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21049 else slotflags |= SLOTMSGFLAG_PRESERVED;
21050 }
21051 else if(scripts.find(playermap[i].scriptname) != scripts.end())
21052 playermap[i].format = SCRIPT_FORMAT_DEFAULT;
21053 else // Unloaded
21054 {
21055 playermap[i].format = SCRIPT_FORMAT_INVALID;
21056 slotflags |= SLOTMSGFLAG_MISSING;
21057 }
21058 }
21059 16 playermap[i].update();
21060 16 }
21061
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSCREEN-1; i++)
21062 {
21063
2/2
✓ Branch 0 taken 1018 times.
✓ Branch 1 taken 2 times.
1020 if(screenmap[i].isEmpty())
21064 1018 sprintf(temp, "Slot %d:", i+1);
21065 else
21066 {
21067 2 sprintf(temp, "Slot %d:", i+1);
21068
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(screenmap[i].isZASM())
21069 {
21070 if(screenmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21071 else slotflags |= SLOTMSGFLAG_PRESERVED;
21072 }
21073
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if(scripts.find(screenmap[i].scriptname) != scripts.end())
21074 2 screenmap[i].format = SCRIPT_FORMAT_DEFAULT;
21075 else // Previously loaded script not found
21076 {
21077 screenmap[i].format = SCRIPT_FORMAT_INVALID;
21078 slotflags |= SLOTMSGFLAG_MISSING;
21079 }
21080 }
21081 1020 screenmap[i].slotname = temp;
21082 1020 screenmap[i].update();
21083 1020 }
21084
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSDMAP-1; i++)
21085 {
21086
2/2
✓ Branch 0 taken 1018 times.
✓ Branch 1 taken 2 times.
1020 if(dmapmap[i].isEmpty())
21087 1018 sprintf(temp, "Slot %d:", i+1);
21088 else
21089 {
21090 2 sprintf(temp, "Slot %d:", i+1);
21091
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if(dmapmap[i].isZASM())
21092 {
21093 if(dmapmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21094 else slotflags |= SLOTMSGFLAG_PRESERVED;
21095 }
21096
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 else if(scripts.find(dmapmap[i].scriptname) != scripts.end())
21097 2 dmapmap[i].format = SCRIPT_FORMAT_DEFAULT;
21098 else // Previously loaded script not found
21099 {
21100 dmapmap[i].format = SCRIPT_FORMAT_INVALID;
21101 slotflags |= SLOTMSGFLAG_MISSING;
21102 }
21103 }
21104 1020 dmapmap[i].slotname = temp;
21105 1020 dmapmap[i].update();
21106 1020 }
21107
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSITEMSPRITE-1; i++)
21108 {
21109
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(itemspritemap[i].isEmpty())
21110 1020 sprintf(temp, "Slot %d:", i+1);
21111 else
21112 {
21113 sprintf(temp, "Slot %d:", i+1);
21114 if(itemspritemap[i].isZASM())
21115 {
21116 if(itemspritemap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21117 else slotflags |= SLOTMSGFLAG_PRESERVED;
21118 }
21119 else if(scripts.find(itemspritemap[i].scriptname) != scripts.end())
21120 itemspritemap[i].format = SCRIPT_FORMAT_DEFAULT;
21121 else // Previously loaded script not found
21122 {
21123 itemspritemap[i].format = SCRIPT_FORMAT_INVALID;
21124 slotflags |= SLOTMSGFLAG_MISSING;
21125 }
21126 }
21127 1020 itemspritemap[i].slotname = temp;
21128 1020 itemspritemap[i].update();
21129 1020 }
21130
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTSCOMBODATA-1; i++)
21131 {
21132
1/2
✓ Branch 0 taken 2044 times.
✗ Branch 1 not taken.
2044 if(comboscriptmap[i].isEmpty())
21133 2044 sprintf(temp, "Slot %d:", i+1);
21134 else
21135 {
21136 sprintf(temp, "Slot %d:", i+1);
21137 if(comboscriptmap[i].isZASM())
21138 {
21139 if(comboscriptmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21140 else slotflags |= SLOTMSGFLAG_PRESERVED;
21141 }
21142 else if(scripts.find(comboscriptmap[i].scriptname) != scripts.end())
21143 comboscriptmap[i].format = SCRIPT_FORMAT_DEFAULT;
21144 else // Previously loaded script not found
21145 {
21146 comboscriptmap[i].format = SCRIPT_FORMAT_INVALID;
21147 slotflags |= SLOTMSGFLAG_MISSING;
21148 }
21149 }
21150 2044 comboscriptmap[i].slotname = temp;
21151 2044 comboscriptmap[i].update();
21152 2044 }
21153
2/2
✓ Branch 0 taken 2044 times.
✓ Branch 1 taken 4 times.
2048 for(int32_t i = 0; i < NUMSCRIPTSGENERIC-1; i++)
21154 {
21155
2/2
✓ Branch 0 taken 2039 times.
✓ Branch 1 taken 5 times.
2044 if(genericmap[i].isEmpty())
21156 2039 sprintf(temp, "Slot %d:", i+1);
21157 else
21158 {
21159 5 sprintf(temp, "Slot %d:", i+1);
21160
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 5 times.
5 if(genericmap[i].isZASM())
21161 {
21162 if(genericmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21163 else slotflags |= SLOTMSGFLAG_PRESERVED;
21164 }
21165
1/2
✓ Branch 0 taken 5 times.
✗ Branch 1 not taken.
5 else if(scripts.find(genericmap[i].scriptname) != scripts.end())
21166 5 genericmap[i].format = SCRIPT_FORMAT_DEFAULT;
21167 else // Previously loaded script not found
21168 {
21169 genericmap[i].format = SCRIPT_FORMAT_INVALID;
21170 slotflags |= SLOTMSGFLAG_MISSING;
21171 }
21172 }
21173 2044 genericmap[i].slotname = temp;
21174 2044 genericmap[i].update();
21175 2044 }
21176
2/2
✓ Branch 0 taken 1020 times.
✓ Branch 1 taken 4 times.
1024 for(int32_t i = 0; i < NUMSCRIPTSSUBSCREEN-1; i++)
21177 {
21178
1/2
✓ Branch 0 taken 1020 times.
✗ Branch 1 not taken.
1020 if(subscreenmap[i].isEmpty())
21179 1020 sprintf(temp, "Slot %d:", i+1);
21180 else
21181 {
21182 sprintf(temp, "Slot %d:", i+1);
21183 if(subscreenmap[i].isZASM())
21184 {
21185 if(subscreenmap[i].isImportedZASM()) slotflags |= SLOTMSGFLAG_IMPORTED;
21186 else slotflags |= SLOTMSGFLAG_PRESERVED;
21187 }
21188 else if(scripts.find(subscreenmap[i].scriptname) != scripts.end())
21189 subscreenmap[i].format = SCRIPT_FORMAT_DEFAULT;
21190 else // Previously loaded script not found
21191 {
21192 subscreenmap[i].format = SCRIPT_FORMAT_INVALID;
21193 slotflags |= SLOTMSGFLAG_MISSING;
21194 }
21195 }
21196 1020 subscreenmap[i].slotname = temp;
21197 1020 subscreenmap[i].update();
21198 1020 }
21199 4 return slotflags;
21200 }
21201
21202 void doClearSlots(byte* flags);
21203
21204 extern byte compile_success_sample, compile_error_sample,
21205 compile_finish_sample, compile_audio_volume;
21206 static map<string, disassembled_script_data> *doslot_scripts = nullptr;
21207 14340 bool handle_slot(script_slot_data& slotdata, int indx, script_data** scriptdata)
21208 {
21209
2/2
✓ Branch 0 taken 98 times.
✓ Branch 1 taken 14242 times.
14340 if(slotdata.hasScriptData())
21210 {
21211 98 string scriptstr;
21212
2/4
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
98 (*doslot_scripts)[slotdata.scriptname].write(scriptstr, doslots_log_output, false, doslots_comment_output);
21213
2/4
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
✗ Branch 3 not taken.
98 if (parse_script_string(scriptdata[indx],scriptstr,false) != D_O_K)
21214 return false;
21215
21216
2/6
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 98 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
98 if(slotdata.isDisassembled()) scriptdata[indx]->meta.setFlag(ZMETA_DISASSEMBLED);
21217
2/6
✓ Branch 0 taken 98 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 98 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
98 else if(slotdata.isImportedZASM()) scriptdata[indx]->meta.setFlag(ZMETA_IMPORTED);
21218
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 98 times.
98 }
21219
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14242 times.
14242 else if(scriptdata[indx])
21220 {
21221
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14242 times.
14242 delete scriptdata[indx];
21222 // script_data::id is not used in editor, so should be fine for now.
21223
1/2
✓ Branch 0 taken 14242 times.
✗ Branch 1 not taken.
14242 scriptdata[indx] = new script_data(ScriptType::None, 0);
21224 14242 }
21225 14340 return true;
21226 14340 }
21227 52 bool handle_slot_map(map<int32_t, script_slot_data>& mp, int offs, script_data** scriptdata)
21228 {
21229
2/2
✓ Branch 0 taken 14340 times.
✓ Branch 1 taken 52 times.
14392 for(auto it = mp.begin(); it != mp.end(); it++)
21230 {
21231
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 14340 times.
14340 if(!handle_slot(it->second, it->first+offs, scriptdata))
21232 return false;
21233 14340 }
21234 52 return true;
21235 52 }
21236
21237 void smart_slot_named(map<string, disassembled_script_data> &scripts,
21238 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
21239 std::string* slotnames, int slotstart, int slotend)
21240 {
21241 for(int q = slotstart; q < slotend; ++q)
21242 {
21243 auto& lval = mp[q];
21244 if(!lval.isEmpty())
21245 continue; //occupied, leave alone
21246 bool done = false;
21247 if(!done) //Check case-sensitive
21248 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
21249 {
21250 auto const& rval = scriptnames[rind];
21251 if(rval == "<none>") continue;
21252 if(rval == slotnames[q])
21253 { //Perfect match
21254 lval.updateName(rval);
21255 lval.format = scripts[lval.scriptname].format;
21256 done = true;
21257 break;
21258 }
21259 }
21260 if(!done) //Check case-insensitive
21261 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
21262 {
21263 auto const& rval = scriptnames[rind];
21264 if(rval == "<none>") continue;
21265 string lc_rv = rval, lc_slot = slotnames[q];
21266 lowerstr(lc_rv);
21267 lowerstr(lc_slot);
21268 if(lc_rv == lc_slot)
21269 { //Insensitive match
21270 lval.updateName(rval);
21271 lval.format = scripts[lval.scriptname].format;
21272 break;
21273 }
21274 }
21275 }
21276 }
21277 void smart_slot_type(map<string, disassembled_script_data> &scripts,
21278 vector<string> const& scriptnames, map<int32_t, script_slot_data>& mp,
21279 int slotcount)
21280 {
21281 for(size_t rind = 0; rind < scriptnames.size(); ++rind)
21282 {
21283 auto const& rval = scriptnames[rind];
21284 if(rval == "<none>") continue;
21285 script_slot_data* first_open_slot = nullptr;
21286 bool done = false;
21287 for(int q = 0; q < slotcount; ++q)
21288 {
21289 auto& lval = mp[q];
21290 if(lval.isEmpty())
21291 {
21292 if(!first_open_slot)
21293 first_open_slot = &lval;
21294 }
21295 else if(lval.scriptname == rval)
21296 {
21297 done = true;
21298 break;
21299 }
21300 }
21301 if(!done)
21302 {
21303 if(!first_open_slot)
21304 break; //no slots left to assign to!
21305 first_open_slot->updateName(rval);
21306 first_open_slot->format = scripts[first_open_slot->scriptname].format;
21307 }
21308 }
21309 }
21310
21311 4 bool do_slots(map<string, disassembled_script_data> &scripts, int assign_mode)
21312 {
21313 4 large_dialog(assignscript_dlg);
21314 4 int32_t ret = 3;
21315 4 char slots_msg[SLOTMSG_SIZE] = {0};
21316 4 byte slotflags = reload_scripts(scripts);
21317 4 setup_scriptslot_dlg(slots_msg, slotflags);
21318 4 bool retval = false;
21319
21320 4 popup_zqdialog_start();
21321
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 while(!assign_mode)
21322 {
21323 slotflags = reload_scripts(scripts);
21324 ret = do_zqdialog(assignscript_dlg, ret);
21325
21326 switch(ret)
21327 {
21328 case 0:
21329 case 2:
21330 //Cancel
21331 goto exit_do_slots;
21332
21333 case 3: goto auto_do_slots;
21334
21335 case 6:
21336 //<<, FFC
21337 {
21338 int32_t lind = assignscript_dlg[4].d1;
21339 int32_t rind = assignscript_dlg[5].d1;
21340
21341 if(lind < 0 || rind < 0)
21342 break;
21343
21344 if(asffcscripts[rind] == "<none>")
21345 {
21346 ffcmap[lind].scriptname = "";
21347 ffcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21348 }
21349 else
21350 {
21351 ffcmap[lind].updateName(asffcscripts[rind]);
21352 ffcmap[lind].format = scripts[ffcmap[lind].scriptname].format;
21353 }
21354
21355 break;
21356 }
21357 case 9:
21358 //<<, Global
21359 {
21360 int32_t lind = assignscript_dlg[7].d1;
21361 int32_t rind = assignscript_dlg[8].d1;
21362
21363 if(lind < 0 || rind < 0)
21364 break;
21365
21366 if(lind == 0)
21367 {
21368 jwin_alert("Error","ZScript reserves this slot.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
21369 break;
21370 }
21371
21372 if(asglobalscripts[rind] == "<none>")
21373 {
21374 globalmap[lind].scriptname = "";
21375 globalmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21376 }
21377 else
21378 {
21379 globalmap[lind].updateName(asglobalscripts[rind]);
21380 globalmap[lind].format = scripts[globalmap[lind].scriptname].format;
21381 }
21382
21383 break;
21384 }
21385 case 12:
21386 //<<, ITEM
21387 {
21388 int32_t lind = assignscript_dlg[10].d1;
21389 int32_t rind = assignscript_dlg[11].d1;
21390
21391 if(lind < 0 || rind < 0)
21392 break;
21393
21394 if(asitemscripts[rind] == "<none>")
21395 {
21396 itemmap[lind].scriptname = "";
21397 itemmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21398 }
21399 else
21400 {
21401 itemmap[lind].updateName(asitemscripts[rind]);
21402 itemmap[lind].format = scripts[itemmap[lind].scriptname].format;
21403 }
21404
21405 break;
21406 }
21407 case 20:
21408 //<<, NPC
21409 {
21410 int32_t lind = assignscript_dlg[18].d1;
21411 int32_t rind = assignscript_dlg[19].d1;
21412
21413 if(lind < 0 || rind < 0)
21414 break;
21415
21416 if(asnpcscripts[rind] == "<none>")
21417 {
21418 npcmap[lind].scriptname = "";
21419 npcmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21420 }
21421 else
21422 {
21423 npcmap[lind].updateName(asnpcscripts[rind]);
21424 npcmap[lind].format = scripts[npcmap[lind].scriptname].format;
21425 }
21426
21427 break;
21428 }
21429 case 23:
21430 //<<, LWeapon
21431 {
21432 int32_t lind = assignscript_dlg[21].d1;
21433 int32_t rind = assignscript_dlg[22].d1;
21434
21435 if(lind < 0 || rind < 0)
21436 break;
21437
21438 if(aslweaponscripts[rind] == "<none>")
21439 {
21440 lwpnmap[lind].scriptname = "";
21441 lwpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21442 }
21443 else
21444 {
21445 lwpnmap[lind].updateName(aslweaponscripts[rind]);
21446 lwpnmap[lind].format = scripts[lwpnmap[lind].scriptname].format;
21447 }
21448
21449 break;
21450 }
21451 case 26:
21452 //<<, EWeapon
21453 {
21454 int32_t lind = assignscript_dlg[24].d1;
21455 int32_t rind = assignscript_dlg[25].d1;
21456
21457 if(lind < 0 || rind < 0)
21458 break;
21459
21460 if(aseweaponscripts[rind] == "<none>")
21461 {
21462 ewpnmap[lind].scriptname = "";
21463 ewpnmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21464 }
21465 else
21466 {
21467 ewpnmap[lind].updateName(aseweaponscripts[rind]);
21468 ewpnmap[lind].format = scripts[ewpnmap[lind].scriptname].format;
21469 }
21470
21471 break;
21472 }
21473 case 29:
21474 //<<, Hero
21475 {
21476 int32_t lind = assignscript_dlg[27].d1;
21477 int32_t rind = assignscript_dlg[28].d1;
21478
21479 if(lind < 0 || rind < 0)
21480 break;
21481
21482 if(asplayerscripts[rind] == "<none>")
21483 {
21484 playermap[lind].scriptname = "";
21485 playermap[lind].format = SCRIPT_FORMAT_DEFAULT;
21486 }
21487 else
21488 {
21489 playermap[lind].updateName(asplayerscripts[rind]);
21490 playermap[lind].format = scripts[playermap[lind].scriptname].format;
21491 }
21492
21493 break;
21494 }
21495 case 32:
21496 //<<, Screendata
21497 {
21498 int32_t lind = assignscript_dlg[30].d1;
21499 int32_t rind = assignscript_dlg[31].d1;
21500
21501 if(lind < 0 || rind < 0)
21502 break;
21503
21504 if(asscreenscripts[rind] == "<none>")
21505 {
21506 screenmap[lind].scriptname = "";
21507 screenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21508 }
21509 else
21510 {
21511 screenmap[lind].updateName(asscreenscripts[rind]);
21512 screenmap[lind].format = scripts[screenmap[lind].scriptname].format;
21513 }
21514
21515 break;
21516 }
21517 case 35:
21518 //<<, dmapdata
21519 {
21520 int32_t lind = assignscript_dlg[33].d1;
21521 int32_t rind = assignscript_dlg[34].d1;
21522
21523 if(lind < 0 || rind < 0)
21524 break;
21525
21526 if(asdmapscripts[rind] == "<none>")
21527 {
21528 dmapmap[lind].scriptname = "";
21529 dmapmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21530 }
21531 else
21532 {
21533 dmapmap[lind].updateName(asdmapscripts[rind]);
21534 dmapmap[lind].format = scripts[dmapmap[lind].scriptname].format;
21535 }
21536
21537 break;
21538 }
21539 case 38:
21540 //<<, itemsprite
21541 {
21542 int32_t lind = assignscript_dlg[36].d1;
21543 int32_t rind = assignscript_dlg[37].d1;
21544
21545 if(lind < 0 || rind < 0)
21546 break;
21547
21548 if(asitemspritescripts[rind] == "<none>")
21549 {
21550 itemspritemap[lind].scriptname = "";
21551 itemspritemap[lind].format = SCRIPT_FORMAT_DEFAULT;
21552 }
21553 else
21554 {
21555 itemspritemap[lind].updateName(asitemspritescripts[rind]);
21556 itemspritemap[lind].format = scripts[itemspritemap[lind].scriptname].format;
21557 }
21558
21559 break;
21560 }
21561 case 41:
21562 //<<, comboscript
21563 {
21564 int32_t lind = assignscript_dlg[39].d1;
21565 int32_t rind = assignscript_dlg[40].d1;
21566
21567 if(lind < 0 || rind < 0)
21568 break;
21569
21570 if(ascomboscripts[rind] == "<none>")
21571 {
21572 comboscriptmap[lind].scriptname = "";
21573 comboscriptmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21574 }
21575 else
21576 {
21577 comboscriptmap[lind].updateName(ascomboscripts[rind]);
21578 comboscriptmap[lind].format = scripts[comboscriptmap[lind].scriptname].format;
21579 }
21580
21581 break;
21582 }
21583 case 47:
21584 //<<, generic script
21585 {
21586 int32_t lind = assignscript_dlg[45].d1;
21587 int32_t rind = assignscript_dlg[46].d1;
21588
21589 if(lind < 0 || rind < 0)
21590 break;
21591
21592 if(asgenericscripts[rind] == "<none>")
21593 {
21594 genericmap[lind].scriptname = "";
21595 genericmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21596 }
21597 else
21598 {
21599 genericmap[lind].updateName(asgenericscripts[rind]);
21600 genericmap[lind].format = scripts[genericmap[lind].scriptname].format;
21601 }
21602
21603 break;
21604 }
21605 case 50:
21606 //<<, subscreen script
21607 {
21608 int32_t lind = assignscript_dlg[48].d1;
21609 int32_t rind = assignscript_dlg[49].d1;
21610
21611 if(lind < 0 || rind < 0)
21612 break;
21613
21614 if(assubscreenscripts[rind] == "<none>")
21615 {
21616 subscreenmap[lind].scriptname = "";
21617 subscreenmap[lind].format = SCRIPT_FORMAT_DEFAULT;
21618 }
21619 else
21620 {
21621 subscreenmap[lind].updateName(assubscreenscripts[rind]);
21622 subscreenmap[lind].format = scripts[subscreenmap[lind].scriptname].format;
21623 }
21624
21625 break;
21626 }
21627
21628 case 42:
21629 //Script Info, information
21630 {
21631 disassembled_script_data* target = nullptr;
21632 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21633 {
21634 default:
21635 case 0: //FFC
21636 {
21637 int32_t id = assignscript_dlg[4].d1;
21638 if(id > -1 && ffcmap[id].hasScriptData())
21639 {
21640 target = &(scripts[ffcmap[id].scriptname]);
21641 }
21642 break;
21643 }
21644 case 1: //Global
21645 {
21646 int32_t id = assignscript_dlg[7].d1;
21647 if(id > -1 && globalmap[id].hasScriptData())
21648 {
21649 target = &(scripts[globalmap[id].scriptname]);
21650 }
21651 break;
21652 }
21653 case 2: //Item
21654 {
21655 int32_t id = assignscript_dlg[10].d1;
21656 if(id > -1 && itemmap[id].hasScriptData())
21657 {
21658 target = &(scripts[itemmap[id].scriptname]);
21659 }
21660 break;
21661 }
21662 case 3: //npc
21663 {
21664 int32_t id = assignscript_dlg[19].d1;
21665 if(id > -1 && npcmap[id].hasScriptData())
21666 {
21667 target = &(scripts[npcmap[id].scriptname]);
21668 }
21669 break;
21670 }
21671 case 4: //lweapon
21672 {
21673 int32_t id = assignscript_dlg[21].d1;
21674 if(id > -1 && lwpnmap[id].hasScriptData())
21675 {
21676 target = &(scripts[lwpnmap[id].scriptname]);
21677 }
21678 break;
21679 }
21680 case 5: //eweapon
21681 {
21682 int32_t id = assignscript_dlg[24].d1;
21683 if(id > -1 && ewpnmap[id].hasScriptData())
21684 {
21685 target = &(scripts[ewpnmap[id].scriptname]);
21686 }
21687 break;
21688 }
21689 case 6: //hero
21690 {
21691 int32_t id = assignscript_dlg[27].d1;
21692 if(id > -1 && playermap[id].hasScriptData())
21693 {
21694 target = &(scripts[playermap[id].scriptname]);
21695 }
21696 break;
21697 }
21698 case 7: //dmap
21699 {
21700 int32_t id = assignscript_dlg[33].d1;
21701 if(id > -1 && dmapmap[id].hasScriptData())
21702 {
21703 target = &(scripts[dmapmap[id].scriptname]);
21704 }
21705 break;
21706 }
21707 case 8: //screen
21708 {
21709 int32_t id = assignscript_dlg[30].d1;
21710 if(id > -1 && screenmap[id].hasScriptData())
21711 {
21712 target = &(scripts[screenmap[id].scriptname]);
21713 }
21714 break;
21715 }
21716 case 9: //itemsprite
21717 {
21718 int32_t id = assignscript_dlg[36].d1;
21719 if(id > -1 && itemspritemap[id].hasScriptData())
21720 {
21721 target = &(scripts[itemspritemap[id].scriptname]);
21722 }
21723 break;
21724 }
21725 case 10: //combo
21726 {
21727 int32_t id = assignscript_dlg[39].d1;
21728 if(id > -1 && comboscriptmap[id].hasScriptData())
21729 {
21730 target = &(scripts[comboscriptmap[id].scriptname]);
21731 }
21732 break;
21733 }
21734 case 11: //Generic
21735 {
21736 int32_t id = assignscript_dlg[45].d1;
21737 if(id > -1 && genericmap[id].hasScriptData())
21738 {
21739 target = &(scripts[genericmap[id].scriptname]);
21740 }
21741 break;
21742 }
21743 case 12: //Subscreen
21744 {
21745 int32_t id = assignscript_dlg[48].d1;
21746 if(id > -1 && subscreenmap[id].hasScriptData())
21747 {
21748 target = &(scripts[subscreenmap[id].scriptname]);
21749 }
21750 break;
21751 }
21752 }
21753 zasm_meta* meta = target ? &target->first : nullptr;
21754 if(devpwd() && CHECK_CTRL_CMD)
21755 {
21756 string str;
21757 target->write(str, false, false, (assignscript_dlg[51].flags == D_SELECTED), true);
21758 set_al_clipboard(str);
21759 displayinfo("Clipboard Copy","Copied ZASM of selected script to clipboard");
21760 }
21761 else if(meta)
21762 showScriptInfo(meta);
21763 break;
21764 }
21765
21766 case 43:
21767 //Script Info, information
21768 {
21769 disassembled_script_data* target = NULL;
21770 switch(get_selected_tab((TABPANEL*)assignscript_dlg[1].dp))
21771 {
21772 default:
21773 case 0: //FFC
21774 {
21775 int32_t id = assignscript_dlg[5].d1;
21776 if(id < 0 || asffcscripts[id] == "<none>" || asffcscripts[id].at(0) == '-') break;
21777 target = &(scripts[asffcscripts[id]]);
21778 break;
21779 }
21780 case 1: //Global
21781 {
21782 int32_t id = assignscript_dlg[8].d1;
21783 if(id < 0 || asglobalscripts[id] == "<none>" || asglobalscripts[id].at(0) == '-') break;
21784 target = &(scripts[asglobalscripts[id]]);
21785 break;
21786 }
21787 case 2: //Item
21788 {
21789 int32_t id = assignscript_dlg[11].d1;
21790 if(id < 0 || asitemscripts[id] == "<none>" || asitemscripts[id].at(0) == '-') break;
21791 target = &(scripts[asitemscripts[id]]);
21792 break;
21793 }
21794 case 3: //npc
21795 {
21796 int32_t id = assignscript_dlg[20].d1;
21797 if(id < 0 || asnpcscripts[id] == "<none>" || asnpcscripts[id].at(0) == '-') break;
21798 target = &(scripts[asnpcscripts[id]]);
21799 break;
21800 }
21801 case 4: //lweapon
21802 {
21803 int32_t id = assignscript_dlg[22].d1;
21804 if(id < 0 || aslweaponscripts[id] == "<none>" || aslweaponscripts[id].at(0) == '-') break;
21805 target = &(scripts[aslweaponscripts[id]]);
21806 break;
21807 }
21808 case 5: //eweapon
21809 {
21810 int32_t id = assignscript_dlg[25].d1;
21811 if(id < 0 || aseweaponscripts[id] == "<none>" || aseweaponscripts[id].at(0) == '-') break;
21812 target = &(scripts[aseweaponscripts[id]]);
21813 break;
21814 }
21815 case 6: //hero
21816 {
21817 int32_t id = assignscript_dlg[28].d1;
21818 if(id < 0 || asplayerscripts[id] == "<none>" || asplayerscripts[id].at(0) == '-') break;
21819 target = &(scripts[asplayerscripts[id]]);
21820 break;
21821 }
21822 case 7: //dmap
21823 {
21824 int32_t id = assignscript_dlg[34].d1;
21825 if(id < 0 || asdmapscripts[id] == "<none>" || asdmapscripts[id].at(0) == '-') break;
21826 target = &(scripts[asdmapscripts[id]]);
21827 break;
21828 }
21829 case 8: //screen
21830 {
21831 int32_t id = assignscript_dlg[31].d1;
21832 if(id < 0 || asscreenscripts[id] == "<none>" || asscreenscripts[id].at(0) == '-') break;
21833 target = &(scripts[asscreenscripts[id]]);
21834 break;
21835 }
21836 case 9: //itemsprite
21837 {
21838 int32_t id = assignscript_dlg[37].d1;
21839 if(id < 0 || asitemspritescripts[id] == "<none>" || asitemspritescripts[id].at(0) == '-') break;
21840 target = &(scripts[asitemspritescripts[id]]);
21841 break;
21842 }
21843 case 10: //combo
21844 {
21845 int32_t id = assignscript_dlg[40].d1;
21846 if(id < 0 || ascomboscripts[id] == "<none>" || ascomboscripts[id].at(0) == '-') break;
21847 target = &(scripts[ascomboscripts[id]]);
21848 break;
21849 }
21850 case 11: //generic
21851 {
21852 int32_t id = assignscript_dlg[46].d1;
21853 if(id < 0 || asgenericscripts[id] == "<none>" || asgenericscripts[id].at(0) == '-') break;
21854 target = &(scripts[asgenericscripts[id]]);
21855 break;
21856 }
21857 case 12: //subscreen
21858 {
21859 int32_t id = assignscript_dlg[49].d1;
21860 if(id < 0 || assubscreenscripts[id] == "<none>" || assubscreenscripts[id].at(0) == '-') break;
21861 target = &(scripts[assubscreenscripts[id]]);
21862 break;
21863 }
21864 }
21865 zasm_meta* meta = target ? &target->first : nullptr;
21866 if(devpwd() && CHECK_CTRL_CMD)
21867 {
21868 string str;
21869 target->write(str, false, false, (assignscript_dlg[51].flags == D_SELECTED), true);
21870 set_al_clipboard(str);
21871 displayinfo("Clipboard Copy","Copied ZASM of selected script to clipboard");
21872 }
21873 else if(meta)
21874 showScriptInfo(meta);
21875 break;
21876 }
21877
21878 case 44:
21879 //Clear, clear slots of current type- after a confirmation.
21880 {
21881 doClearSlots(&slotflags);
21882 break;
21883 }
21884 }
21885 }
21886
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(assign_mode == 2) //Smart Assign
21887 {
21888 //For global/hero scripts, match slot names if unoccupied
21889 smart_slot_named(scripts, asglobalscripts, globalmap, global_slotnames, 1, NUMSCRIPTGLOBAL);
21890 smart_slot_named(scripts, asplayerscripts, playermap, player_slotnames, 0, NUMSCRIPTHERO-1);
21891 //For other scripts, assign all un-assigned scripts
21892 smart_slot_type(scripts, asffcscripts, ffcmap, NUMSCRIPTFFC-1);
21893 smart_slot_type(scripts, asitemscripts, itemmap, NUMSCRIPTITEM-1);
21894 smart_slot_type(scripts, asnpcscripts, npcmap, NUMSCRIPTGUYS-1);
21895 smart_slot_type(scripts, aslweaponscripts, lwpnmap, NUMSCRIPTWEAPONS-1);
21896 smart_slot_type(scripts, aseweaponscripts, ewpnmap, NUMSCRIPTWEAPONS-1);
21897 smart_slot_type(scripts, asscreenscripts, screenmap, NUMSCRIPTSCREEN-1);
21898 smart_slot_type(scripts, asdmapscripts, dmapmap, NUMSCRIPTSDMAP-1);
21899 smart_slot_type(scripts, asitemspritescripts, itemspritemap, NUMSCRIPTSITEMSPRITE-1);
21900 smart_slot_type(scripts, ascomboscripts, comboscriptmap, NUMSCRIPTSCOMBODATA-1);
21901 smart_slot_type(scripts, asgenericscripts, genericmap, NUMSCRIPTSGENERIC-1);
21902 smart_slot_type(scripts, assubscreenscripts, subscreenmap, NUMSCRIPTSSUBSCREEN-1);
21903 }
21904 auto_do_slots:
21905 4 doslots_log_output = (assignscript_dlg[13].flags == D_SELECTED);
21906 4 doslots_comment_output = (assignscript_dlg[51].flags == D_SELECTED);
21907 4 doslot_scripts = &scripts;
21908 //OK
21909 {
21910 4 auto start_assign_time = std::chrono::steady_clock::now();
21911
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(ffcmap, 1, ffscripts))
21912 goto exit_do_slots;
21913
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(globalmap, 0, globalscripts))
21914 goto exit_do_slots;
21915
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(itemmap, 1, itemscripts))
21916 goto exit_do_slots;
21917
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(npcmap, 1, guyscripts))
21918 goto exit_do_slots;
21919
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(lwpnmap, 1, lwpnscripts))
21920 goto exit_do_slots;
21921
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(ewpnmap, 1, ewpnscripts))
21922 goto exit_do_slots;
21923
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(playermap, 1, playerscripts))
21924 goto exit_do_slots;
21925
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(dmapmap, 1, dmapscripts))
21926 goto exit_do_slots;
21927
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(screenmap, 1, screenscripts))
21928 goto exit_do_slots;
21929
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(itemspritemap, 1, itemspritescripts))
21930 goto exit_do_slots;
21931
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(comboscriptmap, 1, comboscripts))
21932 goto exit_do_slots;
21933
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(genericmap, 1, genericscripts))
21934 goto exit_do_slots;
21935
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!handle_slot_map(subscreenmap, 1, subscreenscripts))
21936 goto exit_do_slots;
21937
21938 4 auto end_assign_time = std::chrono::steady_clock::now();
21939 4 int compile_time_ms = std::chrono::duration_cast<std::chrono::milliseconds>(end_assign_time - start_assign_time).count();
21940 4 al_trace("Assign Slots took %d ms\n", compile_time_ms);
21941 4 char buf[256] = {0};
21942 8 sprintf(buf, "ZScripts successfully loaded into script slots"
21943 4 "\nAssign Slots took %d ms", compile_time_ms);
21944 4 compile_finish_sample = vbound(zc_get_config("Compiler","compile_finish_sample",20),0,255);
21945 4 compile_audio_volume = vbound(zc_get_config("Compiler","compile_audio_volume",200),0,255);
21946
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if ( compile_finish_sample > 0 )
21947 {
21948
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(sfxdat)
21949 sfx_voice[compile_finish_sample]=allocate_voice((SAMPLE*)sfxdata[compile_finish_sample].dat);
21950 4 else sfx_voice[compile_finish_sample]=allocate_voice(&customsfxdata[compile_finish_sample]);
21951 4 voice_set_volume(sfx_voice[compile_finish_sample], compile_audio_volume);
21952 4 voice_start(sfx_voice[compile_finish_sample]);
21953 4 }
21954
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if(!assign_mode)
21955 InfoDialog("Slots Assigned",buf).show();
21956
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if ( compile_finish_sample > 0 )
21957 {
21958
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4 times.
4 if(sfx_voice[compile_finish_sample]!=-1)
21959 {
21960 4 deallocate_voice(sfx_voice[compile_finish_sample]);
21961 4 sfx_voice[compile_finish_sample]=-1;
21962 4 }
21963 4 }
21964 4 build_biffs_list();
21965 4 build_biitems_list();
21966 4 retval = true;
21967 4 goto exit_do_slots;
21968 }
21969 exit_do_slots:
21970 4 doslot_scripts = nullptr;
21971 4 popup_zqdialog_end();
21972 4 return retval;
21973 }
21974
21975 static char slottype_str_buf[32];
21976
21977 const char *slottype_list(int32_t index, int32_t *list_size)
21978 {
21979 if(index >= 0)
21980 {
21981 bound(index,0,num_types-1);
21982
21983 switch(index)
21984 {
21985 case type_ffc:
21986 strcpy(slottype_str_buf, "FFC");
21987 break;
21988 case type_global:
21989 strcpy(slottype_str_buf, "Global");
21990 break;
21991 case type_itemdata:
21992 strcpy(slottype_str_buf, "Item");
21993 break;
21994 case type_npc:
21995 strcpy(slottype_str_buf, "NPC");
21996 break;
21997 case type_lweapon:
21998 strcpy(slottype_str_buf, "LWeapon");
21999 break;
22000 case type_eweapon:
22001 strcpy(slottype_str_buf, "EWeapon");
22002 break;
22003 case type_hero:
22004 strcpy(slottype_str_buf, "Hero");
22005 break;
22006 case type_dmap:
22007 strcpy(slottype_str_buf, "DMap");
22008 break;
22009 case type_screen:
22010 strcpy(slottype_str_buf, "Screen");
22011 break;
22012 case type_itemsprite:
22013 strcpy(slottype_str_buf, "ItemSprite");
22014 break;
22015 case type_combo:
22016 strcpy(slottype_str_buf, "Combo");
22017 break;
22018 case type_generic:
22019 strcpy(slottype_str_buf, "Generic");
22020 break;
22021 case type_subscreen:
22022 strcpy(slottype_str_buf, "Subscreen");
22023 break;
22024 }
22025
22026 return slottype_str_buf;
22027 }
22028 *list_size = 11;
22029 return NULL;
22030 }
22031 9 static ListData slottype_sel_list(slottype_list, &font);
22032
22033 static DIALOG clearslots_dlg[] =
22034 {
22035 9 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Clear Slots", NULL, NULL },
22036 9 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
22037 9 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22038 9 { jwin_droplist_proc, 50, 28+16, 70, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
22039 9 { jwin_radio_proc, 40, 34+00, 81, 9, vc(14), vc(1), 0, D_SELECTED, 0, 0, (void *) "Clear Script Type:", NULL, NULL },
22040 9 { jwin_radio_proc, 40, 34+32, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Missing (--) Slots", NULL, NULL },
22041 9 { jwin_radio_proc, 40, 34+48, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Preserved (++) Slots", NULL, NULL },
22042 9 { jwin_radio_proc, 40, 34+64, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear Imported (==) Slots", NULL, NULL },
22043 9 { jwin_radio_proc, 40, 34+80, 81, 9, vc(14), vc(1), 0, 0, 0, 0, (void *) "Clear All", NULL, NULL },
22044 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22045 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22046 };
22047
22048 void doClearSlots(byte* flags)
22049 {
22050 //{ Setup
22051 clearslots_dlg[0].dp2=get_zc_font(font_lfont);
22052 clearslots_dlg[3].d1 = get_selected_tab((TABPANEL*)assignscript_dlg[1].dp); //Default to current tab's type
22053 clearslots_dlg[4].flags |= D_SELECTED;
22054 clearslots_dlg[5].flags &= ~D_SELECTED;
22055 clearslots_dlg[6].flags &= ~D_SELECTED;
22056 clearslots_dlg[7].flags &= ~D_SELECTED;
22057 clearslots_dlg[8].flags &= ~D_SELECTED;
22058 if(((*flags) & SLOTMSGFLAG_MISSING) == 0)
22059 clearslots_dlg[5].flags |= D_DISABLED;
22060 else
22061 clearslots_dlg[5].flags &= ~D_DISABLED;
22062 if(((*flags) & SLOTMSGFLAG_PRESERVED) == 0)
22063 clearslots_dlg[6].flags |= D_DISABLED;
22064 else
22065 clearslots_dlg[6].flags &= ~D_DISABLED;
22066 if(((*flags) & SLOTMSGFLAG_IMPORTED) == 0)
22067 clearslots_dlg[7].flags |= D_DISABLED;
22068 else
22069 clearslots_dlg[7].flags &= ~D_DISABLED;
22070 //}
22071
22072 large_dialog(clearslots_dlg);
22073
22074 if(do_zqdialog(clearslots_dlg,2)==1)
22075 {
22076 int32_t q = 3;
22077 while((clearslots_dlg[++q].flags & D_SELECTED) == 0);
22078 switch(q)
22079 {
22080 case 4: //Clear type
22081 {
22082 clearAllSlots(clearslots_dlg[3].d1);
22083 break;
22084 }
22085 case 5: //Clear Missing
22086 {
22087 for(int32_t q = 0; q <= 10; ++q)
22088 clearAllSlots(q,SLOTMSGFLAG_MISSING);
22089 break;
22090 }
22091 case 6: //Clear Preserved
22092 {
22093 for(int32_t q = 0; q <= 10; ++q)
22094 clearAllSlots(q,SLOTMSGFLAG_PRESERVED);
22095 break;
22096 }
22097 case 7: //Clear Imported ZASM
22098 {
22099 for(int32_t q = 0; q <= 10; ++q)
22100 clearAllSlots(q,SLOTMSGFLAG_IMPORTED);
22101 break;
22102 }
22103 case 8: //Clear ALL
22104 {
22105 for(int32_t q = 0; q <= 10; ++q)
22106 clearAllSlots(q);
22107 break;
22108 }
22109 }
22110 }
22111 }
22112
22113 static DIALOG exportzasm_dlg[] =
22114 {
22115 9 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Export ZASM", NULL, NULL },
22116 9 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
22117 9 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22118 9 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
22119 9 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
22120 9 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
22121 9 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
22122 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22123 };
22124
22125 static DIALOG importzasm_dlg[] =
22126 {
22127 9 { jwin_win_proc, 0, 0, 200, 159, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Import ZASM", NULL, NULL },
22128 9 { jwin_button_proc, 35, 132, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "Confirm", NULL, NULL },
22129 9 { jwin_button_proc, 104, 132, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22130 9 { jwin_droplist_proc, 50, 28+16, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, D_EXIT, 0, 0, (void *) &slottype_sel_list, NULL, NULL },
22131 9 { jwin_droplist_proc, 50, 28+48, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 0, 0, NULL, NULL, NULL },
22132 // 5
22133 9 { jwin_text_proc, 50, 28+8, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Type:", NULL, NULL },
22134 9 { jwin_text_proc, 50, 28+40, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Slot:", NULL, NULL },
22135 9 { jwin_text_proc, 50, 28+72, 16, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Script Name:", NULL, NULL },
22136 9 { jwin_edit_proc, 50, 28+80, 100, 16, jwin_pal[jcTEXTFG], jwin_pal[jcTEXTBG], 0, 0, 19, 0, NULL, NULL, NULL },
22137
22138 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22139 };
22140 extern ListData itemscript_list;
22141 extern ListData itemspritescript_list;
22142 extern ListData lweaponscript_list;
22143 extern ListData npcscript_list;
22144 extern ListData eweaponscript_list;
22145 extern ListData comboscript_list;
22146
22147 static EXT_LIST zasm_extlist[] =
22148 {
22149 { (char *)"ZASM Files (*.zasm)", (char *)"zasm" },
22150 { NULL, NULL }
22151 };
22152
22153 int32_t onImportZASM()
22154 {
22155 importzasm_dlg[0].dp2 = get_zc_font(font_lfont);
22156 importzasm_dlg[4].dp = (void*)&ffscript_list;
22157 if(!prompt_for_existing_file_compat("Import Script (.zasm)","zasm",zasm_extlist,datapath,false))
22158 {
22159 return D_O_K;
22160 }
22161 script_data *temp_slot = new script_data(ScriptType::None, 0);
22162 if(parse_script_file(temp_slot, temppath, false) == D_CLOSE)
22163 {
22164 jwin_alert("Error","Failed to parse specified file!",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
22165 delete temp_slot;
22166 return D_O_K;
22167 }
22168
22169 std::string namebuf;
22170 if(temp_slot->meta.valid()) //Found metadata
22171 {
22172 importzasm_dlg[3].d1 = getType(temp_slot->meta.script_type);
22173 namebuf = temp_slot->meta.script_name;
22174 switch(importzasm_dlg[3].d1)
22175 {
22176 default: //Shouldn't occur, but to be safe
22177 case type_ffc:
22178 importzasm_dlg[4].dp = (void*)&ffscript_sel_dlg_list;
22179 break;
22180 case type_global:
22181 importzasm_dlg[4].dp = (void*)&gscript_sel_dlg_list;
22182 break;
22183 case type_itemdata:
22184 importzasm_dlg[4].dp = (void*)&itemscript_sel_dlg_list;
22185 break;
22186 case type_npc:
22187 importzasm_dlg[4].dp = (void*)&npcscript_sel_dlg_list;
22188 break;
22189 case type_lweapon:
22190 importzasm_dlg[4].dp = (void*)&lweaponscript_sel_dlg_list;
22191 break;
22192 case type_eweapon:
22193 importzasm_dlg[4].dp = (void*)&eweaponscript_sel_dlg_list;
22194 break;
22195 case type_hero:
22196 importzasm_dlg[4].dp = (void*)&playerscript_sel_dlg_list;
22197 break;
22198 case type_dmap:
22199 importzasm_dlg[4].dp = (void*)&dmapscript_sel_dlg_list;
22200 break;
22201 case type_screen:
22202 importzasm_dlg[4].dp = (void*)&screenscript_sel_dlg_list;
22203 break;
22204 case type_itemsprite:
22205 importzasm_dlg[4].dp = (void*)&itemspritescript_sel_dlg_list;
22206 break;
22207 case type_combo:
22208 importzasm_dlg[4].dp = (void*)&comboscript_sel_dlg_list;
22209 break;
22210 }
22211 importzasm_dlg[4].d1 = 0;
22212 }
22213 else
22214 {
22215 importzasm_dlg[3].d1 = 0;
22216 importzasm_dlg[4].dp = (void*)&ffscript_list;
22217 importzasm_dlg[4].d1 = 0;
22218 }
22219 importzasm_dlg[8].dp = (void*)namebuf.c_str();
22220 bool confirmed = false;
22221 int32_t indx = 1;
22222 while(!confirmed)
22223 {
22224 large_dialog(importzasm_dlg);
22225 indx = do_zqdialog(importzasm_dlg, indx);
22226 switch(indx)
22227 {
22228 case 1: //confirm; exit dlg
22229 {
22230 if(!namebuf[0]) break; //No name?
22231 script_data **slot = NULL;
22232 script_slot_data *map = NULL;
22233 //{ Find script choice
22234 int32_t scriptInd = importzasm_dlg[4].d1;
22235 switch(importzasm_dlg[3].d1)
22236 {
22237 case type_ffc:
22238 slot = &ffscripts[scriptInd];
22239 map = &ffcmap[scriptInd];
22240 break;
22241 case type_global:
22242 slot = &globalscripts[scriptInd];
22243 map = &globalmap[scriptInd];
22244 break;
22245 case type_itemdata:
22246 slot = &itemscripts[scriptInd];
22247 map = &itemmap[scriptInd];
22248 break;
22249 case type_npc:
22250 slot = &guyscripts[scriptInd];
22251 map = &npcmap[scriptInd];
22252 break;
22253 case type_lweapon:
22254 slot = &lwpnscripts[scriptInd];
22255 map = &lwpnmap[scriptInd];
22256 break;
22257 case type_eweapon:
22258 slot = &ewpnscripts[scriptInd];
22259 map = &ewpnmap[scriptInd];
22260 break;
22261 case type_hero:
22262 slot = &playerscripts[scriptInd];
22263 map = &playermap[scriptInd];
22264 break;
22265 case type_dmap:
22266 slot = &dmapscripts[scriptInd];
22267 map = &dmapmap[scriptInd];
22268 break;
22269 case type_screen:
22270 slot = &screenscripts[scriptInd];
22271 map = &screenmap[scriptInd];
22272 break;
22273 case type_itemsprite:
22274 slot = &itemspritescripts[scriptInd];
22275 map = &itemspritemap[scriptInd];
22276 break;
22277 case type_combo:
22278 slot = &comboscripts[scriptInd];
22279 map = &comboscriptmap[scriptInd];
22280 break;
22281 case type_generic:
22282 slot = &genericscripts[scriptInd];
22283 map = &genericmap[scriptInd];
22284 break;
22285 case type_subscreen:
22286 slot = &subscreenscripts[scriptInd];
22287 map = &subscreenmap[scriptInd];
22288 break;
22289 }
22290 //}
22291 if(!slot) break; //Not found?
22292 *slot = std::move(temp_slot);
22293 map->format = SCRIPT_FORMAT_ZASM;
22294 map->updateName(namebuf);
22295 confirmed = true;
22296 break;
22297 }
22298 case 0: case 2: //Close dlg
22299 {
22300 delete temp_slot;
22301 return D_O_K;
22302 }
22303 case 3: //Type select
22304 {
22305 switch(importzasm_dlg[3].d1)
22306 {
22307 default: //Shouldn't occur, but to be safe
22308 case type_ffc:
22309 importzasm_dlg[4].dp = (void*)&ffscript_sel_dlg_list;
22310 break;
22311 case type_global:
22312 importzasm_dlg[4].dp = (void*)&gscript_sel_dlg_list;
22313 break;
22314 case type_itemdata:
22315 importzasm_dlg[4].dp = (void*)&itemscript_sel_dlg_list;
22316 break;
22317 case type_npc:
22318 importzasm_dlg[4].dp = (void*)&npcscript_sel_dlg_list;
22319 break;
22320 case type_lweapon:
22321 importzasm_dlg[4].dp = (void*)&lweaponscript_sel_dlg_list;
22322 break;
22323 case type_eweapon:
22324 importzasm_dlg[4].dp = (void*)&eweaponscript_sel_dlg_list;
22325 break;
22326 case type_hero:
22327 importzasm_dlg[4].dp = (void*)&playerscript_sel_dlg_list;
22328 break;
22329 case type_dmap:
22330 importzasm_dlg[4].dp = (void*)&dmapscript_sel_dlg_list;
22331 break;
22332 case type_screen:
22333 importzasm_dlg[4].dp = (void*)&screenscript_sel_dlg_list;
22334 break;
22335 case type_itemsprite:
22336 importzasm_dlg[4].dp = (void*)&itemspritescript_sel_dlg_list;
22337 break;
22338 case type_combo:
22339 importzasm_dlg[4].dp = (void*)&comboscript_sel_dlg_list;
22340 break;
22341 }
22342 importzasm_dlg[4].d1 = 0;
22343 break;
22344 }
22345 }
22346 }
22347 delete temp_slot;
22348 return D_O_K;
22349 }
22350
22351 6 void center_zscript_dialogs()
22352 {
22353 6 jwin_center_dialog(exportzasm_dlg);
22354 6 jwin_center_dialog(importzasm_dlg);
22355 6 jwin_center_dialog(clearslots_dlg);
22356 6 }
22357
22358 // array of voices, one for each sfx sample in the data file
22359 // 0+ = voice #
22360 // -1 = voice not allocated
22361 int32_t sfx_voice[WAV_COUNT];
22362
22363 void Z_init_sound()
22364 {
22365 for(int32_t i=0; i<WAV_COUNT; i++)
22366 sfx_voice[i]=-1;
22367
22368 // master_volume(digi_volume,midi_volume);
22369 }
22370
22371 // returns number of voices currently allocated
22372 int32_t sfx_count()
22373 {
22374 int32_t c=0;
22375
22376 for(int32_t i=0; i<WAV_COUNT; i++)
22377 if(sfx_voice[i]!=-1)
22378 ++c;
22379
22380 return c;
22381 }
22382
22383 // clean up finished samples
22384 void sfx_cleanup()
22385 {
22386 for(int32_t i=0; i<WAV_COUNT; i++)
22387 if(sfx_voice[i]!=-1 && voice_get_position(sfx_voice[i])<0)
22388 {
22389 deallocate_voice(sfx_voice[i]);
22390 sfx_voice[i]=-1;
22391 }
22392 }
22393
22394 // allocates a voice for the sample "wav_index" (index into zelda.dat)
22395 // if a voice is already allocated (and/or playing), then it just returns true
22396 // Returns true: voice is allocated
22397 // false: unsuccessful
22398 SAMPLE templist[WAV_COUNT];
22399
22400 bool sfx_init(int32_t index)
22401 {
22402 // check index
22403 if(index<1 || index>=WAV_COUNT)
22404 return false;
22405
22406 if(sfx_voice[index]==-1)
22407 {
22408 sfx_voice[index]=allocate_voice(&templist[index]);
22409 }
22410
22411 return sfx_voice[index] != -1;
22412 }
22413
22414 // plays an sfx sample
22415 void sfx(int32_t index,int32_t pan,bool loop,bool restart,int32_t vol,int32_t freq)
22416 {
22417 if(!sfx_init(index))
22418 return;
22419
22420 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
22421 voice_set_pan(sfx_voice[index],pan);
22422
22423 int32_t pos = voice_get_position(sfx_voice[index]);
22424
22425 if(restart) voice_set_position(sfx_voice[index],0);
22426
22427 if(pos<=0)
22428 voice_start(sfx_voice[index]);
22429 }
22430
22431 // start it (in loop mode) if it's not already playing,
22432 // otherwise just leave it in its current position
22433 void cont_sfx(int32_t index)
22434 {
22435 if(!sfx_init(index))
22436 return;
22437
22438 if(voice_get_position(sfx_voice[index])<=0)
22439 {
22440 voice_set_position(sfx_voice[index],0);
22441 voice_set_playmode(sfx_voice[index],PLAYMODE_LOOP);
22442 voice_start(sfx_voice[index]);
22443 }
22444 }
22445
22446 // adjust parameters while playing
22447 void adjust_sfx(int32_t index,int32_t pan,bool loop)
22448 {
22449 if(index<0 || index>=WAV_COUNT || sfx_voice[index]==-1)
22450 return;
22451
22452 voice_set_playmode(sfx_voice[index],loop?PLAYMODE_LOOP:PLAYMODE_PLAY);
22453 voice_set_pan(sfx_voice[index],pan);
22454 }
22455
22456 // pauses a voice
22457 void pause_sfx(int32_t index)
22458 {
22459 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
22460 voice_stop(sfx_voice[index]);
22461 }
22462
22463 // resumes a voice
22464 void resume_sfx(int32_t index)
22465 {
22466 if(index>=0 && index<WAV_COUNT && sfx_voice[index]!=-1)
22467 voice_start(sfx_voice[index]);
22468 }
22469
22470 // pauses all active voices
22471 void pause_all_sfx()
22472 {
22473 for(int32_t i=0; i<WAV_COUNT; i++)
22474 if(sfx_voice[i]!=-1)
22475 voice_stop(sfx_voice[i]);
22476 }
22477
22478 // resumes all paused voices
22479 void resume_all_sfx()
22480 {
22481 for(int32_t i=0; i<WAV_COUNT; i++)
22482 if(sfx_voice[i]!=-1)
22483 voice_start(sfx_voice[i]);
22484 }
22485
22486 // stops an sfx and deallocates the voice
22487 void stop_sfx(int32_t index)
22488 {
22489 if(index<0 || index>=WAV_COUNT)
22490 return;
22491
22492 if(sfx_voice[index]!=-1)
22493 {
22494 deallocate_voice(sfx_voice[index]);
22495 sfx_voice[index]=-1;
22496 }
22497 }
22498
22499 void kill_sfx()
22500 {
22501 for(int32_t i=0; i<WAV_COUNT; i++)
22502 if(sfx_voice[i]!=-1)
22503 {
22504 deallocate_voice(sfx_voice[i]);
22505 sfx_voice[i]=-1;
22506 }
22507 }
22508
22509 int32_t pan(int32_t x)
22510 {
22511 return 128;
22512 /*switch(pan_style)
22513 {
22514 case 0: return 128;
22515 case 1: return vbound((x>>1)+68,0,255);
22516 case 2: return vbound(((x*3)>>2)+36,0,255);
22517 }
22518 return vbound(x,0,255);*/
22519 }
22520
22521
22522 void change_sfx(SAMPLE *sfx1, SAMPLE *sfx2)
22523 {
22524 sfx1->bits = sfx2->bits;
22525 sfx1->stereo = sfx2->stereo;
22526 sfx1->freq = sfx2->freq;
22527 sfx1->priority = sfx2->priority;
22528 sfx1->len = sfx2->len;
22529 sfx1->loop_start = sfx2->loop_start;
22530 sfx1->loop_end = sfx2->loop_end;
22531 sfx1->param = sfx2->param;
22532
22533 if(sfx1->data != NULL)
22534 {
22535 free(sfx1->data);
22536 }
22537
22538 if(sfx2->data == NULL)
22539 sfx1->data = NULL;
22540 else
22541 {
22542 // When quests are saved and loaded, data is written in words.
22543 // If the last byte is dropped, it'll cause the sound to end with
22544 // a click. It could simply be extended and padded with 0, but
22545 // that causes compatibility issues... So we'll cut off
22546 // the last byte and decrease the length.
22547
22548 int32_t len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
22549
22550 while(len%sizeof(word))
22551 {
22552 // sizeof(word) should be 2, so this doesn't really need
22553 // to be a loop, but what the heck.
22554 sfx1->len--;
22555 len = (sfx1->bits==8?1:2)*(sfx1->stereo == 0 ? 1 : 2)*sfx1->len;
22556 }
22557
22558 sfx1->data = malloc(len);
22559 memcpy(sfx1->data, sfx2->data, len);
22560 }
22561 }
22562
22563 bool confirmBox(const char *m1, const char *m2, const char *m3)
22564 {
22565 if(!m3)
22566 {
22567 if(!m2) m2 = "Are you sure?";
22568 else m3 = "Are you sure?";
22569 }
22570 return jwin_alert("Confirmation", m1, m2, m3, "Yes", "No", 'y', 'n', get_zc_font(font_lfont)) == 1;
22571 }
22572
22573 int32_t onSelectSFX()
22574 {
22575 SFXListerDialog(0).show();
22576 refresh(rMAP+rCOMBOS);
22577 return D_O_K;
22578 }
22579
22580 bool saveWAV(int32_t slot, const char *filename)
22581 {
22582 if (slot < 1 || slot >= 511 )
22583 return false;
22584
22585 if (customsfxdata[slot].data == NULL)
22586 return false;
22587
22588 std::ofstream ofs(filename, std::ios::binary);
22589 if (!ofs)
22590 return false;
22591 ofs.write("RIFF",4);
22592 uint32_t samplerate = customsfxdata[slot].freq;
22593 uint16_t channels = customsfxdata[slot].stereo ? 2 : 1;
22594 uint32_t datalen = customsfxdata[slot].len*channels*customsfxdata[slot].bits / 8;
22595 uint32_t size = 36 + datalen;
22596 ofs.write((char *)&size, 4);
22597 ofs.write("WAVE", 4);
22598 ofs.write("fmt ", 4);
22599 uint32_t fmtlen = 16;
22600 ofs.write((char *)&fmtlen, 4);
22601 uint16_t type = 1;
22602 ofs.write((char *)&type, 2);
22603 ofs.write((char *)&channels, 2);
22604 ofs.write((char *)&samplerate, 4);
22605 uint32_t bytespersec = samplerate*channels*customsfxdata[slot].bits / 8;
22606 ofs.write((char *)&bytespersec, 4);
22607 uint16_t blockalign = channels*customsfxdata[slot].bits / 8;
22608 ofs.write((char *)&blockalign, 2);
22609 uint16_t bitspersample = customsfxdata[slot].bits;
22610 ofs.write((char *)&bitspersample, 2);
22611 ofs.write("data", 4);
22612 ofs.write((char *)&datalen, 4);
22613 if (bitspersample == 8)
22614 {
22615 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
22616 {
22617 char data = ((char *)customsfxdata[slot].data)[i];
22618 data ^= 0x80;
22619 ofs.write(&data, 1);
22620 }
22621 }
22622 else if (bitspersample == 16)
22623 {
22624 for (int32_t i = 0; i < (int32_t)customsfxdata[slot].len*channels; i++)
22625 {
22626 uint16_t data = ((uint16_t *)customsfxdata[slot].data)[i];
22627 data ^= 0x8000;
22628 ofs.write((char *)&data, 2);
22629 }
22630 }
22631 else
22632 return false;
22633 return !!ofs;
22634 }
22635
22636 int32_t onEditSFX(int32_t index)
22637 {
22638 call_sfxdata_dialog(index);
22639 return D_O_K;
22640 }
22641
22642 int32_t onMapStyles()
22643 {
22644 call_mapstyles_dialog();
22645 return D_O_K;
22646 }
22647
22648 int32_t d_misccolors_old_proc(int32_t msg,DIALOG *d,int32_t c)
22649 {
22650 //these are here to bypass compiler warnings about unused arguments
22651 c=c;
22652
22653 if(msg==MSG_DRAW)
22654 {
22655 textout_ex(screen,font,"0123456789ABCDEF",d->x+8,d->y,d->fg,d->bg);
22656 textout_ex(screen,font,"0",d->x,d->y+8,d->fg,d->bg);
22657 textout_ex(screen,font,"1",d->x,d->y+16,d->fg,d->bg);
22658 textout_ex(screen,font,"5",d->x,d->y+24,d->fg,d->bg);
22659
22660 for(int32_t i=0; i<32; i++)
22661 {
22662 int32_t px2 = d->x+((i&15)<<3)+8;
22663 int32_t py2 = d->y+((i>>4)<<3)+8;
22664 rectfill(screen,px2,py2,px2+7,py2+7,i);
22665 }
22666
22667 for(int32_t i=0; i<16; i++)
22668 {
22669 int32_t px2 = d->x+(i<<3)+8;
22670 rectfill(screen,px2,d->y+24,px2+7,d->y+31,i+80);
22671 }
22672 }
22673
22674 return D_O_K;
22675 }
22676
22677 int32_t hexclicked=-1;
22678
22679 int32_t d_misccolors_hexedit_proc(int32_t msg,DIALOG *d,int32_t c)
22680 {
22681 switch(msg)
22682 {
22683 case MSG_GOTFOCUS:
22684 hexclicked=((int32_t)(size_t)(d->dp3))+20;
22685 break;
22686
22687 case MSG_LOSTFOCUS:
22688 hexclicked=-1;
22689 break;
22690 }
22691
22692 return d_hexedit_proc(msg,d,c);
22693 }
22694
22695
22696 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c);
22697
22698 static int32_t misccolor1_list[] =
22699 {
22700 // dialog control number
22701 4, 5, 6, 7, 8, 20, 21, 22, 23, 24, 36, 37, 38, 39, 40, -1
22702 };
22703
22704 static int32_t misccolor2_list[] =
22705 {
22706 // dialog control number
22707 9, 10, 11, 12, 13, 25, 26, 27, 28, 29, 41, 42, 43, 44, 45, -1
22708 };
22709
22710 static int32_t misccolor3_list[] =
22711 {
22712 // dialog control number
22713 14, 15, 16, 17, 18, 30, 31, 32, 33, 34, 46, 47, 48, 49, 50, -1
22714 };
22715
22716 static int32_t misccolor4_list[] =
22717 {
22718 19, 35, 51, 54, 55, 56, -1
22719 };
22720
22721 static TABPANEL misccolor_tabs[] =
22722 {
22723 // (text)
22724 { (char *)"1", D_SELECTED, misccolor1_list, 0, NULL },
22725 { (char *)"2", 0, misccolor2_list, 0, NULL },
22726 { (char *)"3", 0, misccolor3_list, 0, NULL },
22727 { (char *)"4", 0, misccolor4_list, 0, NULL },
22728 { NULL, 0, NULL, 0, NULL }
22729 };
22730
22731 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c);
22732
22733 static DIALOG misccolors_dlg[] =
22734 {
22735 // (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp)
22736 9 { jwin_win_proc, 2, 21, 316, 197-23, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Misc Colors", NULL, NULL },
22737 // { jwin_frame_proc, 98-84+1+2, 52+8-6+4, 132, 100, vc(15), vc(1), 0, 0, FR_DEEP, 0, NULL, NULL, NULL },
22738 9 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
22739 9 { d_misccolors_proc, 92-84+1+2, 44+8-6+4, 128+8, 96+8, vc(9), vc(1), 0, 0, 0, 0, NULL, NULL, NULL },
22740 //3
22741 9 { d_misccolors_tab_proc, 150+14-2+10-15, 60-14, 150-10+15, 144-20-10, jwin_pal[jcBOXFG], jwin_pal[jcBOX], 0, 0, 0, 0, (void *) misccolor_tabs, NULL, (void *)misccolors_dlg },
22742 //4
22743 9 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Text:", NULL, NULL },
22744 9 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Caption:", NULL, NULL },
22745 9 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Overworld Minmap:", NULL, NULL },
22746 9 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Background:", NULL, NULL },
22747 9 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 1:", NULL, NULL },
22748 9 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Minimap Foreground 2:", NULL, NULL },
22749 9 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Dark:", NULL, NULL },
22750 9 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "BS Minimap Goal:", NULL, NULL },
22751 9 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Light):", NULL, NULL },
22752 9 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Compass Mark (Dark):", NULL, NULL },
22753 9 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Background:", NULL, NULL },
22754 9 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Subscreen Shadow:", NULL, NULL },
22755 9 { jwin_text_proc, 215-25-12-15, 112-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Triforce Frame:", NULL, NULL },
22756 9 { jwin_text_proc, 215-25-12-15, 130-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Background:", NULL, NULL },
22757 9 { jwin_text_proc, 215-25-12-15, 148-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Big Map Foreground:", NULL, NULL },
22758 9 { jwin_text_proc, 215-25-12-15, 76-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Hero's Position:", NULL, NULL },
22759
22760 //20
22761 9 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)0, },
22762 9 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)1, },
22763 9 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)2, },
22764 9 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)3, },
22765 9 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)4, },
22766 9 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)5, },
22767 9 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)6, },
22768 9 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)7, },
22769 9 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)8, },
22770 9 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)9, },
22771 9 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)10, },
22772 9 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)11, },
22773 9 { d_misccolors_hexedit_proc, 294-25+14+2, 112-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)12, },
22774 9 { d_misccolors_hexedit_proc, 294-25+14+2, 130-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)13, },
22775 9 { d_misccolors_hexedit_proc, 294-25+14+2, 148-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)14, },
22776 9 { d_misccolors_hexedit_proc, 294-25+14+2, 76-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)15, },
22777
22778 //36
22779 9 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22780 9 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22781 9 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22782 9 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22783 9 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22784 9 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22785 9 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22786 9 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22787 9 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22788 9 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22789 9 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22790 9 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22791 9 { jwin_text_proc, 283-25+14+2, 112-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22792 9 { jwin_text_proc, 283-25+14+2, 130-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22793 9 { jwin_text_proc, 283-25+14+2, 148-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22794 9 { jwin_text_proc, 283-25+14+2, 76-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22795
22796 //52
22797 9 { jwin_button_proc, 90, 190-20, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22798 9 { jwin_button_proc, 170, 190-20, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22799 9 { jwin_text_proc, 215-25-12-15, 94-4, 0, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Message Text:", NULL, NULL },
22800 9 { d_misccolors_hexedit_proc, 294-25+14+2, 94-8, 21, 16, vc(11), vc(1), 0, 0, 2, 0, NULL, NULL, (void *)35, },
22801 9 { jwin_text_proc, 283-25+14+2, 94-4, 0, 8, vc(11), vc(1), 0, 0, 2, 0, (void *) "0x", NULL, NULL },
22802 9 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
22803 };
22804
22805 int32_t d_misccolors_tab_proc(int32_t msg,DIALOG *d,int32_t c)
22806 {
22807
22808 switch(msg)
22809 {
22810 case MSG_WANTFOCUS:
22811 return D_WANTFOCUS;
22812 break;
22813 }
22814
22815 return jwin_tab_proc(msg,d,c);
22816 }
22817
22818
22819 int32_t d_misccolors_proc(int32_t msg,DIALOG *d,int32_t c)
22820 {
22821 //these are here to bypass compiler warnings about unused arguments
22822 c=c;
22823 int32_t mul=12;
22824
22825 switch(msg)
22826 {
22827 case MSG_CLICK:
22828 if(hexclicked!=-1)
22829 {
22830 int32_t color_col=vbound(((gui_mouse_x()-d->x-8)/mul),0,15);
22831 int32_t color_row=vbound(((gui_mouse_y()-d->y-10)/mul),0,11);
22832 sprintf((char*)misccolors_dlg[hexclicked].dp,"%X%X",color_row,color_col);
22833 object_message(misccolors_dlg+hexclicked,MSG_DRAW,0);
22834 }
22835
22836 break;
22837
22838 case MSG_DRAW:
22839 for(int32_t i=0; i<10; i++)
22840 {
22841 textprintf_centre_ex(screen,font,d->x+8+4+(i*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22842 }
22843
22844 for(int32_t i=0; i<6; i++)
22845 {
22846 textprintf_centre_ex(screen,font,d->x+8+4+((10+i)*mul),d->y,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22847 }
22848
22849 for(int32_t i=0; i<10; i++)
22850 {
22851 textprintf_right_ex(screen,font,d->x+6,d->y+(i*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%d", i);
22852 }
22853
22854 for(int32_t i=0; i<2; i++)
22855 {
22856 textprintf_right_ex(screen,font,d->x+6,d->y+((i+10)*mul)+10,jwin_pal[jcBOXFG],jwin_pal[jcBOX], "%c", i+'A');
22857 }
22858
22859 jwin_draw_frame(screen,d->x+6,d->y+8,int32_t(132*1.5)-2,int32_t(100*1.5)-2,FR_DEEP);
22860
22861 for(int32_t i=0; i<192; i++)
22862 {
22863 int32_t px2 = d->x+int32_t(((i&15)<<3)*1.5)+8;
22864 int32_t py2 = d->y+int32_t(((i>>4)<<3)*1.5)+8+2;
22865 rectfill(screen,px2,py2,px2+(mul-1),py2+(mul-1),i);
22866 }
22867
22868 break;
22869 }
22870
22871 return D_O_K;
22872 }
22873
22874
22875 int32_t onMiscColors()
22876 {
22877 char buf[17][3];
22878 byte *si = &(QMisc.colors.text);
22879 misccolors_dlg[0].dp2=get_zc_font(font_lfont);
22880
22881 for(int32_t i=0; i<16; i++)
22882 {
22883 sprintf(buf[i],"%02X",*(si++));
22884 sprintf(buf[16], "%02X", QMisc.colors.msgtext);
22885 misccolors_dlg[i+20].dp = buf[i];
22886 misccolors_dlg[55].dp = buf[16];
22887 }
22888
22889 large_dialog(misccolors_dlg);
22890
22891 if(do_zqdialog(misccolors_dlg,0)==52)
22892 {
22893 saved=false;
22894 si = &(QMisc.colors.text);
22895
22896 for(int32_t i=0; i<16; i++)
22897 {
22898 *si = zc_xtoi(buf[i]);
22899 ++si;
22900 }
22901
22902 QMisc.colors.msgtext = zc_xtoi(buf[16]);
22903 }
22904
22905 return D_O_K;
22906 }
22907
22908 // **** Palette cycling ****
22909
22910 static int32_t palclk[3];
22911 static int32_t palpos[3];
22912
22913 26 void reset_pal_cycling()
22914 {
22915
2/2
✓ Branch 0 taken 78 times.
✓ Branch 1 taken 26 times.
104 for(int32_t i=0; i<3; i++)
22916 78 palclk[i]=palpos[i]=0;
22917 26 }
22918
22919 void cycle_palette()
22920 {
22921 if(!get_qr(qr_FADE))
22922 return;
22923
22924 int32_t level = Map.CurrScr()->color;
22925 bool refreshpal = false;
22926
22927 for(int32_t i=0; i<3; i++)
22928 {
22929 palcycle c = QMisc.cycles[level][i];
22930
22931 if(c.count&0xF0)
22932 {
22933 if(++palclk[i] >= c.speed)
22934 {
22935 palclk[i]=0;
22936
22937 if(++palpos[i] >= (c.count>>4))
22938 palpos[i]=0;
22939
22940 byte *si = colordata + CSET(level*pdLEVEL+poFADE1+1+palpos[i])*3;
22941
22942 si += (c.first&15)*3;
22943
22944 for(int32_t col=c.first&15; col<=(c.count&15); col++)
22945 {
22946 RAMpal[CSET(c.first>>4)+col] = _RGB(si);
22947 si+=3;
22948 }
22949
22950 refreshpal = true;
22951 }
22952 }
22953 }
22954
22955 if(refreshpal)
22956 {
22957 rebuild_trans_table();
22958 zc_set_palette_range(RAMpal,0,192,false);
22959 }
22960 }
22961
22962
22963 void doHelp()
22964 {
22965 do_box_edit(helpstr, "ZQuest Help", true, true);
22966 }
22967
22968 int32_t onHelp()
22969 {
22970 restore_mouse();
22971 doHelp();
22972 return D_O_K;
22973 }
22974
22975 void doZstringshelp()
22976 {
22977 do_box_edit(zstringshelpstr, "ZStrings Help", true, true);
22978 }
22979
22980 int32_t onZstringshelp()
22981 {
22982 restore_mouse();
22983 doZstringshelp();
22984 return D_O_K;
22985 }
22986
22987 static DIALOG layerdata_dlg[] =
22988 {
22989 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
22990 { jwin_win_proc, 16-12, 20+32, 288+1+24, 200+1-32-16, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Layer Data", NULL, NULL },
22991 { jwin_button_proc, 170, 180, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
22992 { jwin_button_proc, 90, 180, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
22993 // 3
22994 { jwin_rtext_proc, 72, 88, 40, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Map:", NULL, NULL },
22995 { jwin_rtext_proc, 72, 88+18, 48, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Screen:", NULL, NULL },
22996 { jwin_rtext_proc, 72, 88+36, 56, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "Transparent:", NULL, NULL },
22997 { jwin_ctext_proc, 89, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "1", NULL, NULL },
22998 { jwin_ctext_proc, 89+40, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "2", NULL, NULL },
22999 { jwin_ctext_proc, 89+80, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "3", NULL, NULL },
23000 { jwin_ctext_proc, 89+120, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "4", NULL, NULL },
23001 { jwin_ctext_proc, 89+160, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "5", NULL, NULL },
23002 { jwin_ctext_proc, 89+200, 76, 8, 8, vc(11), vc(1), 0, 0, 0, 0, (void *) "6", NULL, NULL },
23003
23004 //12
23005 { jwin_edit_proc, 76, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23006 { d_hexedit_proc, 76, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
23007 { jwin_check_proc, 76, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
23008
23009 { jwin_edit_proc, 76+40, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23010 { d_hexedit_proc, 76+40, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
23011 { jwin_check_proc, 76+40, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
23012
23013 { jwin_edit_proc, 76+80, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23014 { d_hexedit_proc, 76+80, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
23015 { jwin_check_proc, 76+80, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
23016
23017 { jwin_edit_proc, 76+120, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23018 { d_hexedit_proc, 76+120, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
23019 { jwin_check_proc, 76+120, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
23020
23021 { jwin_edit_proc, 76+160, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23022 { d_hexedit_proc, 76+160, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
23023 { jwin_check_proc, 76+160, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
23024
23025 { jwin_edit_proc, 76+200, 76+8, 32-6, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23026 { d_hexedit_proc, 76+200, 76+18+8, 24-3, 16, vc(12), vc(1), 0, 0, 2, 0, NULL, NULL, NULL },
23027 { jwin_check_proc, 76+200, 76+40+8, 17, 9, vc(12), vc(1), 0, 0, 1, 0, NULL, NULL, NULL },
23028
23029 //30
23030 { jwin_button_proc, 76, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
23031 { jwin_button_proc, 76+40, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
23032 { jwin_button_proc, 76+80, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
23033 { jwin_button_proc, 76+120, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
23034 { jwin_button_proc, 76+160, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
23035 { jwin_button_proc, 76+200, 76+40+18+8, 30, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Auto", NULL, NULL },
23036
23037 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
23038 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
23039
23040 };
23041
23042 int32_t edit_layers(mapscr* tempscr)
23043 {
23044 char buf[6][2][8];
23045 layerdata_dlg[0].dp2 = get_zc_font(font_lfont);
23046
23047 for(int32_t x=0; x<6; x++)
23048 {
23049 sprintf(buf[x][0],"%d",tempscr->layermap[x]);
23050 sprintf(buf[x][1],"%02X",tempscr->layerscreen[x]);
23051 }
23052
23053 for(int32_t x=0; x<6; x++)
23054 {
23055 for(int32_t y=0; y<2; y++)
23056 {
23057 layerdata_dlg[(x*3)+y+12].dp = buf[x][y];
23058 }
23059 }
23060
23061 for(int32_t x=0; x<6; x++)
23062 {
23063 layerdata_dlg[(x*3)+2+12].flags = (tempscr->layeropacity[x]<255) ? D_SELECTED : 0;
23064 }
23065
23066 large_dialog(layerdata_dlg);
23067
23068 int32_t ret=do_zqdialog(layerdata_dlg,0);
23069
23070 if(ret>=2)
23071 {
23072 for(int32_t x=0; x<6; x++)
23073 {
23074
23075 tempscr->layermap[x]=atoi(buf[x][0]);
23076
23077 if(tempscr->layermap[x]>map_count)
23078 {
23079 tempscr->layermap[x]=0;
23080 }
23081
23082 tempscr->layerscreen[x]=zc_xtoi(buf[x][1]);
23083
23084 if(zc_xtoi(buf[x][1])>=MAPSCRS)
23085 {
23086 tempscr->layerscreen[x]=0;
23087 }
23088
23089 // tempscr->layeropacity[x]=layerdata_dlg[(x*9)+8+19].flags & D_SELECTED ? 128:255;
23090 tempscr->layeropacity[x]=layerdata_dlg[(x*3)+2+12].flags & D_SELECTED ? 128:255;
23091 }
23092
23093 // } else if (ret>72&&ret<79) {
23094 // return (ret-72);
23095 }
23096
23097 return ret;
23098 }
23099
23100 static DIALOG autolayer_dlg[] =
23101 {
23102 /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) */
23103 { jwin_win_proc, 64, 32+48, 192+1, 184+1-64, vc(14), vc(1), 0, D_EXIT, 0, 0, (void *) "Autolayer Setup", NULL, NULL },
23104 { jwin_text_proc, 76, 56+48, 136, 8, vc(14), vc(1), 0, 0, 0, 0, (void *) "Map for layer ?: ", NULL, NULL },
23105 { jwin_edit_proc, 212, 56+48, 32, 16, vc(12), vc(1), 0, 0, 3, 0, NULL, NULL, NULL },
23106 { jwin_check_proc, 76, 56+18+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Screens", NULL, NULL },
23107 { jwin_button_proc, 90, 188-12, 61, 21, vc(14), vc(1), 13, D_EXIT, 0, 0, (void *) "OK", NULL, NULL },
23108
23109 //5
23110 { jwin_button_proc, 170, 188-12, 61, 21, vc(14), vc(1), 27, D_EXIT, 0, 0, (void *) "Cancel", NULL, NULL },
23111 { d_keyboard_proc, 0, 0, 0, 0, 0, 0, 0, 0, KEY_F1, 0, (void *) onHelp, NULL, NULL },
23112 { d_timer_proc, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
23113 { jwin_check_proc, 76, 56+28+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Only Blank Layers", NULL, NULL },
23114 { jwin_check_proc, 76, 56+38+48, 153, 8, vc(14), vc(1), 0, D_EXIT, 1, 0, (void *) "Overwrite Layers", NULL, NULL },
23115
23116 //10
23117 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
23118 };
23119 enum
23120 {
23121 autolyr_blankscreens,
23122 autolyr_blanklayers,
23123 autolyr_any
23124 };
23125 void autolayer(mapscr* tempscr, int32_t layer, int32_t al[6][3])
23126 {
23127 char tbuf[80],mlayer[80];
23128 autolayer_dlg[0].dp2=get_zc_font(font_lfont);
23129 sprintf(tbuf, "Map for layer %d: ", layer+1);
23130 autolayer_dlg[1].dp=tbuf;
23131 sprintf(mlayer, "%d", tempscr->layermap[layer]);
23132 autolayer_dlg[2].dp=mlayer;
23133
23134 large_dialog(autolayer_dlg);
23135 int ret, sel = 8, fl = autolyr_blanklayers;
23136 bool running = true;
23137 do
23138 {
23139 SETFLAG(autolayer_dlg[3].flags, D_SELECTED, sel==3);
23140 SETFLAG(autolayer_dlg[8].flags, D_SELECTED, sel==8);
23141 SETFLAG(autolayer_dlg[9].flags, D_SELECTED, sel==9);
23142 switch(ret=do_zqdialog(autolayer_dlg,0))
23143 {
23144 case 4: //OK
23145 {
23146 int32_t lmap=vbound(atoi(mlayer),0,Map.getMapCount());
23147 al[layer][0]=lmap;
23148 tempscr->layermap[layer]=lmap;
23149 tempscr->layerscreen[layer]=Map.getCurrScr();
23150 al[layer][1]=fl;
23151 al[layer][2]=1;
23152 running = false;
23153 break;
23154 }
23155 case 0: case 5: //cancel
23156 running = false;
23157 break;
23158 case 3:
23159 sel = ret;
23160 fl = autolyr_blankscreens;
23161 break;
23162 case 8:
23163 sel = ret;
23164 fl = autolyr_blanklayers;
23165 break;
23166 case 9:
23167 sel = ret;
23168 fl = autolyr_any;
23169 break;
23170 }
23171 }
23172 while(ret != 0 && ret != 4 && ret != 5);
23173 }
23174
23175 int32_t onLayers()
23176 {
23177 mapscr tempscr=*Map.CurrScr();
23178 int32_t al[6][3]; //autolayer[layer][0=map, 1=autolyr_ type, 2=bool go]
23179
23180 for(int32_t i=0; i<6; i++)
23181 {
23182 al[i][0]=tempscr.layermap[i];
23183 al[i][1]=0;
23184 al[i][2]=0;
23185 }
23186
23187 int32_t ret;
23188
23189 do
23190 {
23191 ret=edit_layers(&tempscr);
23192
23193 if(ret>2) //autolayer button
23194 {
23195 autolayer(&tempscr, ret-30, al);
23196 }
23197 }
23198 while(ret>2); //autolayer button
23199
23200 if(ret==2) //OK
23201 {
23202 saved=false;
23203 TheMaps[Map.getCurrMap()*MAPSCRS+Map.getCurrScr()]=tempscr;
23204
23205 for(int32_t i=0; i<6; i++)
23206 {
23207 int32_t tm=tempscr.layermap[i]-1;
23208 int32_t ts=tempscr.layerscreen[i];
23209
23210 if(al[i][2])
23211 {
23212 map_autolayers[Map.getCurrMap()*6+i] = al[i][0];
23213 for(int32_t j=0; j<128; j++)
23214 {
23215 auto& curmapscr = TheMaps[Map.getCurrMap()*MAPSCRS+j];
23216 if(al[i][1] == autolyr_blankscreens && (curmapscr.valid&mVALID))
23217 continue;
23218 else if(al[i][1] == autolyr_blanklayers && curmapscr.layermap[i])
23219 continue;
23220
23221 curmapscr.layermap[i]=al[i][0];
23222 curmapscr.layerscreen[i]=al[i][0]?j:0;
23223 }
23224 }
23225 }
23226 }
23227
23228 // Check that the working layer wasn't just disabled
23229 if(CurrentLayer>0 && tempscr.layermap[CurrentLayer-1]==0)
23230 CurrentLayer=0;
23231
23232 return D_O_K;
23233 }
23234
23235
23236 char *itoa(int32_t i)
23237 {
23238 static char itoaret[500];
23239 sprintf(itoaret, "%d", i);
23240 return itoaret;
23241 }
23242
23243 64 void fps_callback()
23244 {
23245 64 lastfps=framecnt;
23246 64 framecnt=0;
23247 64 }
23248
23249 END_OF_FUNCTION(fps_callback)
23250
23251 //uint32_t col_diff[3*128];
23252 /*
23253 void bestfit_init(void)
23254 {
23255 int32_t i;
23256
23257 for (i=1; i<64; i++)
23258
23259 {
23260 int32_t k = i * i;
23261 col_diff[0 +i] = col_diff[0 +128-i] = k * (59 * 59);
23262 col_diff[128+i] = col_diff[128+128-i] = k * (30 * 30);
23263 col_diff[256+i] = col_diff[256+128-i] = k * (11 * 11);
23264 }
23265 }
23266 */
23267 16 void create_rgb_table2(RGB_MAP *table, AL_CONST PALETTE pal_8bit, void (*callback)(int32_t pos))
23268 {
23269 #define UNUSED 65535
23270 #define LAST 65532
23271
23272 // Allegro has been modified to use an 8 bit palette, but this method and RGB_MAP still use 6 bit.
23273 PALETTE pal;
23274
2/2
✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 16 times.
4112 for (int i = 0; i < 256; i++)
23275 {
23276 4096 pal[i] = pal_8bit[i];
23277 4096 pal[i].r /= 4;
23278 4096 pal[i].g /= 4;
23279 4096 pal[i].b /= 4;
23280 4096 }
23281
23282 /* macro add adds to single linked list */
23283 #define add(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
23284 (first != LAST ? (next[last] = (i)) : (first = (i))), \
23285 (last = (i))) : 0)
23286
23287 /* same but w/o checking for first element */
23288 #define add1(i) (next[(i)] == UNUSED ? (next[(i)] = LAST, \
23289 next[last] = (i), \
23290 (last = (i))) : 0)
23291 /* calculates distance between two colors */
23292 #define dist(a1, a2, a3, b1, b2, b3) \
23293 (col_diff[ ((a2) - (b2)) & 0x7F] + \
23294 (col_diff + 128)[((a1) - (b1)) & 0x7F] + \
23295 (col_diff + 256)[((a3) - (b3)) & 0x7F])
23296
23297 /* converts r,g,b to position in array and back */
23298 #define pos(r, g, b) \
23299 (((r) / 2) * 32 * 32 + ((g) / 2) * 32 + ((b) / 2))
23300
23301 #define depos(pal, r, g, b) \
23302 ((b) = ((pal) & 31) * 2, \
23303 (g) = (((pal) >> 5) & 31) * 2, \
23304 (r) = (((pal) >> 10) & 31) * 2)
23305
23306 /* is current color better than pal1? */
23307 #define better(r1, g1, b1, pal1) \
23308 (((int32_t)dist((r1), (g1), (b1), \
23309 (pal1).r, (pal1).g, (pal1).b)) > (int32_t)dist2)
23310
23311 /* checking of position */
23312 #define dopos(rp, gp, bp, ts) \
23313 if ((rp > -1 || r > 0) && (rp < 1 || r < 61) && \
23314 (gp > -1 || g > 0) && (gp < 1 || g < 61) && \
23315 (bp > -1 || b > 0) && (bp < 1 || b < 61)) \
23316 { \
23317 i = first + rp * 32 * 32 + gp * 32 + bp; \
23318 if (!data[i]) \
23319 { \
23320 data[i] = val; \
23321 add1(i); \
23322 } \
23323 else if ((ts) && (data[i] != val)) \
23324 { \
23325 dist2 = (rp ? (col_diff+128)[(r+2*rp-pal[val].r) & 0x7F] : r2) + \
23326 (gp ? (col_diff )[(g+2*gp-pal[val].g) & 0x7F] : g2) + \
23327 (bp ? (col_diff+256)[(b+2*bp-pal[val].b) & 0x7F] : b2); \
23328 if (better((r+2*rp), (g+2*gp), (b+2*bp), pal[data[i]])) \
23329 { \
23330 data[i] = val; \
23331 add1(i); \
23332 } \
23333 } \
23334 }
23335
23336 int32_t i, curr, r, g, b, val, dist2;
23337 uint32_t r2, g2, b2;
23338 uint16_t next[32*32*32];
23339 uint8_t *data;
23340 16 int32_t first = LAST;
23341 16 int32_t last = LAST;
23342 16 int32_t count = 0;
23343 16 int32_t cbcount = 0;
23344
23345 #define AVERAGE_COUNT 18000
23346
23347
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 7 times.
16 if(col_diff[1] == 0)
23348 9 bestfit_init();
23349
23350 16 memset(next, 255, sizeof(next));
23351 16 memset(table->data, 0, sizeof(char)*32*32*32);
23352
23353
23354 16 data = (uint8_t *)table->data;
23355
23356 /* add starting seeds for floodfill */
23357
2/2
✓ Branch 0 taken 4080 times.
✓ Branch 1 taken 16 times.
4096 for(i=1; i<PAL_SIZE; i++)
23358 {
23359 4080 curr = pos(pal[i].r, pal[i].g, pal[i].b);
23360
23361
2/2
✓ Branch 0 taken 3277 times.
✓ Branch 1 taken 803 times.
4080 if(next[curr] == UNUSED)
23362 {
23363 803 data[curr] = i;
23364
3/4
✓ Branch 0 taken 803 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 787 times.
✓ Branch 3 taken 16 times.
803 add(curr);
23365 803 }
23366 4080 }
23367
23368 /* main floodfill: two versions of loop for faster growing in blue axis */
23369 // while (first != LAST) {
23370
2/2
✓ Branch 0 taken 345751 times.
✓ Branch 1 taken 16 times.
345767 while(first < LAST)
23371 {
23372 345751 depos(first, r, g, b);
23373
23374 /* calculate distance of current color */
23375 345751 val = data[first];
23376 345751 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
23377 345751 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
23378 345751 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
23379
23380 /* try to grow to all directions */
23381 #ifdef _MSC_VER
23382 #pragma warning(disable:4127)
23383 #endif
23384
11/12
✓ Branch 0 taken 11162 times.
✓ Branch 1 taken 334589 times.
✓ Branch 2 taken 321351 times.
✓ Branch 3 taken 13238 times.
✓ Branch 4 taken 13238 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 270171 times.
✓ Branch 7 taken 51180 times.
✓ Branch 8 taken 13513 times.
✓ Branch 9 taken 37667 times.
✓ Branch 10 taken 24335 times.
✓ Branch 11 taken 13332 times.
667102 dopos(0, 0, 1, 1);
23385
11/12
✓ Branch 0 taken 10212 times.
✓ Branch 1 taken 335539 times.
✓ Branch 2 taken 323929 times.
✓ Branch 3 taken 11610 times.
✓ Branch 4 taken 11610 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 282930 times.
✓ Branch 7 taken 40999 times.
✓ Branch 8 taken 15157 times.
✓ Branch 9 taken 25842 times.
✓ Branch 10 taken 17738 times.
✓ Branch 11 taken 8104 times.
669680 dopos(0, 0,-1, 1);
23386
11/12
✓ Branch 0 taken 11132 times.
✓ Branch 1 taken 334619 times.
✓ Branch 2 taken 326158 times.
✓ Branch 3 taken 8461 times.
✓ Branch 4 taken 8461 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 269916 times.
✓ Branch 7 taken 56242 times.
✓ Branch 8 taken 36091 times.
✓ Branch 9 taken 20151 times.
✓ Branch 10 taken 12887 times.
✓ Branch 11 taken 7264 times.
671909 dopos(1, 0, 0, 1);
23387
11/12
✓ Branch 0 taken 11214 times.
✓ Branch 1 taken 334537 times.
✓ Branch 2 taken 325829 times.
✓ Branch 3 taken 8708 times.
✓ Branch 4 taken 8708 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 271706 times.
✓ Branch 7 taken 54123 times.
✓ Branch 8 taken 35521 times.
✓ Branch 9 taken 18602 times.
✓ Branch 10 taken 12211 times.
✓ Branch 11 taken 6391 times.
671580 dopos(-1, 0, 0, 1);
23388
11/12
✓ Branch 0 taken 11211 times.
✓ Branch 1 taken 334540 times.
✓ Branch 2 taken 300525 times.
✓ Branch 3 taken 34015 times.
✓ Branch 4 taken 34015 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 227897 times.
✓ Branch 7 taken 72628 times.
✓ Branch 8 taken 59107 times.
✓ Branch 9 taken 13521 times.
✓ Branch 10 taken 9050 times.
✓ Branch 11 taken 4471 times.
646276 dopos(0, 1, 0, 1);
23389
11/12
✓ Branch 0 taken 10170 times.
✓ Branch 1 taken 335581 times.
✓ Branch 2 taken 306141 times.
✓ Branch 3 taken 29440 times.
✓ Branch 4 taken 29440 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 234335 times.
✓ Branch 7 taken 71806 times.
✓ Branch 8 taken 60451 times.
✓ Branch 9 taken 11355 times.
✓ Branch 10 taken 7225 times.
✓ Branch 11 taken 4130 times.
651892 dopos(0,-1, 0, 1);
23390 #ifdef _MSC_VER
23391 #pragma warning(default:4127)
23392 #endif
23393
23394 /* faster growing of blue direction */
23395
4/4
✓ Branch 0 taken 335539 times.
✓ Branch 1 taken 10212 times.
✓ Branch 2 taken 15157 times.
✓ Branch 3 taken 320382 times.
345751 if((b > 0) && (data[first-1] == val))
23396 {
23397 320382 b -= 2;
23398 320382 first--;
23399 320382 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
23400
23401 #ifdef _MSC_VER
23402 #pragma warning(disable:4127)
23403 #endif
23404
5/6
✓ Branch 0 taken 10456 times.
✓ Branch 1 taken 309926 times.
✓ Branch 2 taken 282087 times.
✓ Branch 3 taken 27839 times.
✓ Branch 4 taken 27839 times.
✗ Branch 5 not taken.
602469 dopos(-1, 0, 0, 0);
23405
5/6
✓ Branch 0 taken 10412 times.
✓ Branch 1 taken 309970 times.
✓ Branch 2 taken 282376 times.
✓ Branch 3 taken 27594 times.
✓ Branch 4 taken 27594 times.
✗ Branch 5 not taken.
602758 dopos(1, 0, 0, 0);
23406
5/6
✓ Branch 0 taken 9512 times.
✓ Branch 1 taken 310870 times.
✓ Branch 2 taken 273715 times.
✓ Branch 3 taken 37155 times.
✓ Branch 4 taken 37155 times.
✗ Branch 5 not taken.
594097 dopos(0,-1, 0, 0);
23407
5/6
✓ Branch 0 taken 10506 times.
✓ Branch 1 taken 309876 times.
✓ Branch 2 taken 260078 times.
✓ Branch 3 taken 49798 times.
✓ Branch 4 taken 49798 times.
✗ Branch 5 not taken.
580460 dopos(0, 1, 0, 0);
23408 #ifdef _MSC_VER
23409 #pragma warning(default:4127)
23410 #endif
23411
23412 320382 first++;
23413 320382 }
23414
23415 /* get next from list */
23416 345751 i = first;
23417 345751 first = next[first];
23418 345751 next[i] = UNUSED;
23419
23420 /* second version of loop */
23421 // if (first != LAST) {
23422
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 345744 times.
345751 if(first < LAST)
23423 {
23424
23425 345744 depos(first, r, g, b);
23426
23427 345744 val = data[first];
23428 345744 r2 = (col_diff+128)[((pal[val].r)-(r)) & 0x7F];
23429 345744 g2 = (col_diff)[((pal[val].g)-(g)) & 0x7F];
23430 345744 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7F];
23431
23432 #ifdef _MSC_VER
23433 #pragma warning(disable:4127)
23434 #endif
23435
11/12
✓ Branch 0 taken 10804 times.
✓ Branch 1 taken 334940 times.
✓ Branch 2 taken 319569 times.
✓ Branch 3 taken 15371 times.
✓ Branch 4 taken 15371 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 268344 times.
✓ Branch 7 taken 51225 times.
✓ Branch 8 taken 13566 times.
✓ Branch 9 taken 37659 times.
✓ Branch 10 taken 24368 times.
✓ Branch 11 taken 13291 times.
665313 dopos(0, 0, 1, 1);
23436
11/12
✓ Branch 0 taken 10096 times.
✓ Branch 1 taken 335648 times.
✓ Branch 2 taken 325830 times.
✓ Branch 3 taken 9818 times.
✓ Branch 4 taken 9818 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 284821 times.
✓ Branch 7 taken 41009 times.
✓ Branch 8 taken 15430 times.
✓ Branch 9 taken 25579 times.
✓ Branch 10 taken 17651 times.
✓ Branch 11 taken 7928 times.
671574 dopos(0, 0,-1, 1);
23437
11/12
✓ Branch 0 taken 11295 times.
✓ Branch 1 taken 334449 times.
✓ Branch 2 taken 325748 times.
✓ Branch 3 taken 8701 times.
✓ Branch 4 taken 8701 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 269393 times.
✓ Branch 7 taken 56355 times.
✓ Branch 8 taken 36238 times.
✓ Branch 9 taken 20117 times.
✓ Branch 10 taken 12934 times.
✓ Branch 11 taken 7183 times.
671492 dopos(1, 0, 0, 1);
23438
11/12
✓ Branch 0 taken 11110 times.
✓ Branch 1 taken 334634 times.
✓ Branch 2 taken 326124 times.
✓ Branch 3 taken 8510 times.
✓ Branch 4 taken 8510 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 271978 times.
✓ Branch 7 taken 54146 times.
✓ Branch 8 taken 35687 times.
✓ Branch 9 taken 18459 times.
✓ Branch 10 taken 12384 times.
✓ Branch 11 taken 6075 times.
671868 dopos(-1, 0, 0, 1);
23439
11/12
✓ Branch 0 taken 11190 times.
✓ Branch 1 taken 334554 times.
✓ Branch 2 taken 301123 times.
✓ Branch 3 taken 33431 times.
✓ Branch 4 taken 33431 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 228796 times.
✓ Branch 7 taken 72327 times.
✓ Branch 8 taken 59007 times.
✓ Branch 9 taken 13320 times.
✓ Branch 10 taken 8989 times.
✓ Branch 11 taken 4331 times.
646867 dopos(0, 1, 0, 1);
23440
11/12
✓ Branch 0 taken 10015 times.
✓ Branch 1 taken 335729 times.
✓ Branch 2 taken 307306 times.
✓ Branch 3 taken 28423 times.
✓ Branch 4 taken 28423 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 235237 times.
✓ Branch 7 taken 72069 times.
✓ Branch 8 taken 60691 times.
✓ Branch 9 taken 11378 times.
✓ Branch 10 taken 7435 times.
✓ Branch 11 taken 3943 times.
653050 dopos(0,-1, 0, 1);
23441 #ifdef _MSC_VER
23442 #pragma warning(default:4127)
23443 #endif
23444
23445
4/4
✓ Branch 0 taken 334940 times.
✓ Branch 1 taken 10804 times.
✓ Branch 2 taken 13566 times.
✓ Branch 3 taken 321374 times.
345744 if((b < 61) && (data[first + 1] == val))
23446 {
23447 321374 b += 2;
23448 321374 first++;
23449 321374 b2 = (col_diff+256)[((pal[val].b)-(b)) & 0x7f];
23450 #ifdef _MSC_VER
23451 #pragma warning(disable:4127)
23452 #endif
23453
5/6
✓ Branch 0 taken 10389 times.
✓ Branch 1 taken 310985 times.
✓ Branch 2 taken 280531 times.
✓ Branch 3 taken 30454 times.
✓ Branch 4 taken 30454 times.
✗ Branch 5 not taken.
601905 dopos(-1, 0, 0, 0);
23454
5/6
✓ Branch 0 taken 10490 times.
✓ Branch 1 taken 310884 times.
✓ Branch 2 taken 272651 times.
✓ Branch 3 taken 38233 times.
✓ Branch 4 taken 38233 times.
✗ Branch 5 not taken.
594025 dopos(1, 0, 0, 0);
23455
5/6
✓ Branch 0 taken 9314 times.
✓ Branch 1 taken 312060 times.
✓ Branch 2 taken 260694 times.
✓ Branch 3 taken 51366 times.
✓ Branch 4 taken 51366 times.
✗ Branch 5 not taken.
582068 dopos(0,-1, 0, 0);
23456
5/6
✓ Branch 0 taken 10584 times.
✓ Branch 1 taken 310790 times.
✓ Branch 2 taken 259470 times.
✓ Branch 3 taken 51320 times.
✓ Branch 4 taken 51320 times.
✗ Branch 5 not taken.
580844 dopos(0, 1, 0, 0);
23457 #ifdef _MSC_VER
23458 #pragma warning(default:4127)
23459 #endif
23460
23461 321374 first--;
23462 321374 }
23463
23464 345744 i = first;
23465 345744 first = next[first];
23466 345744 next[i] = UNUSED;
23467 345744 }
23468
23469 345751 count++;
23470
23471
2/2
✓ Branch 0 taken 341639 times.
✓ Branch 1 taken 4112 times.
345751 if(count == (cbcount+1)*AVERAGE_COUNT/256)
23472 {
23473
2/2
✓ Branch 0 taken 16 times.
✓ Branch 1 taken 4096 times.
4112 if(cbcount < 256)
23474 {
23475
1/2
✓ Branch 0 taken 4096 times.
✗ Branch 1 not taken.
4096 if(callback)
23476 callback(cbcount);
23477
23478 4096 cbcount++;
23479 4096 }
23480 4112 }
23481
23482 }
23483
23484 /* only the transparent (pink) color can be mapped to index 0 */
23485
1/6
✗ Branch 0 not taken.
✓ Branch 1 taken 16 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
16 if((pal[0].r == 63) && (pal[0].g == 0) && (pal[0].b == 63))
23486 table->data[31][0][31] = 0;
23487
23488
1/2
✓ Branch 0 taken 16 times.
✗ Branch 1 not taken.
16 if(callback)
23489 while(cbcount < 256)
23490 callback(cbcount++);
23491 16 }
23492
23493 16 void rebuild_trans_table()
23494 {
23495 16 create_rgb_table2(&zq_rgb_table, RAMpal, NULL);
23496 16 create_zc_trans_table(&trans_table, RAMpal, 128, 128, 128);
23497 16 memcpy(&trans_table2, &trans_table, sizeof(COLOR_MAP));
23498
23499
2/2
✓ Branch 0 taken 4096 times.
✓ Branch 1 taken 16 times.
4112 for(int32_t q=0; q<PAL_SIZE; q++)
23500 {
23501 4096 trans_table2.data[0][q] = q;
23502 4096 trans_table2.data[q][q] = q;
23503 4096 }
23504 16 }
23505
23506 int32_t isFullScreen()
23507 {
23508 return !is_windowed_mode();
23509 }
23510
23511 void hit_close_button()
23512 {
23513 close_button_quit=true;
23514 return;
23515 }
23516
23517 extern bool dirty_screen;
23518
23519 void anim_hw_screen(bool force)
23520 {
23521 // if (force || myvsync)
23522 {
23523 ++cpoolbrush_index;
23524
23525 if(prv_mode)
23526 {
23527 if(Map.get_prvtime())
23528 {
23529 Map.set_prvtime(Map.get_prvtime()-1);
23530
23531 if(!Map.get_prvtime())
23532 {
23533 prv_warp=1;
23534 }
23535 }
23536 }
23537 if(AnimationOn)
23538 {
23539 animate_combos();
23540 update_freeform_combos();
23541 }
23542
23543 if(CycleOn)
23544 cycle_palette();
23545
23546 animate_coords();
23547 update_hw_screen();
23548 }
23549 }
23550
23551 void custom_vsync()
23552 {
23553 anim_hw_screen(true);
23554 }
23555
23556 void switch_out()
23557 {
23558 zcmusic_pause(zcmusic, ZCM_PAUSE);
23559 zc_midi_pause();
23560 }
23561
23562 void switch_in()
23563 {
23564 if(exiting_program)
23565 return;
23566 zcmusic_pause(zcmusic, ZCM_RESUME);
23567 zc_midi_resume();
23568 }
23569
23570 void Z_eventlog(const char *format,...)
23571 {
23572 format=format; //to prevent a compiler warning
23573 }
23574
23575 int32_t get_currdmap()
23576 {
23577 return zinit.start_dmap;
23578 }
23579
23580 int32_t get_dlevel()
23581 {
23582 return DMaps[zinit.start_dmap].level;
23583 }
23584
23585 int32_t get_currscr()
23586 {
23587 return Map.getCurrScr();
23588 }
23589
23590 int32_t get_currmap()
23591 {
23592 return Map.getCurrMap();
23593 }
23594
23595 int32_t get_homescr()
23596 {
23597 return DMaps[zinit.start_dmap].cont;
23598 }
23599
23600 int current_item(int item_type, bool checkmagic, bool jinx_check, bool check_bunny)
23601 {
23602 //TODO remove as special case?? -DD
23603 if(item_type==itype_shield)
23604 {
23605 return 2;
23606 }
23607
23608 int id = current_item_id(item_type, checkmagic, jinx_check, check_bunny);
23609 return id > -1 ? itemsbuf[id].fam_type : 0;
23610 }
23611
23612 int current_item_power(int itemtype, bool checkmagic, bool jinx_check, bool check_bunny)
23613 {
23614 if (game)
23615 {
23616 int result = current_item_id(itemtype, checkmagic, jinx_check, check_bunny);
23617 return (result<0) ? 0 : itemsbuf[result].power;
23618 }
23619 return 1;
23620 }
23621
23622 int32_t current_item_id(int32_t itemtype, bool, bool, bool)
23623 {
23624 if (game)
23625 {
23626 int32_t result = -1;
23627 int32_t highestlevel = -1;
23628
23629 for (int32_t i = 0; i < MAXITEMS; i++)
23630 {
23631 if ((zq_ignore_item_ownership || game->get_item(i)) && itemsbuf[i].family == itemtype)
23632 {
23633 if (itemsbuf[i].fam_type >= highestlevel)
23634 {
23635 highestlevel = itemsbuf[i].fam_type;
23636 result = i;
23637 }
23638 }
23639 }
23640 return result;
23641 }
23642 for(int32_t i=0; i<MAXITEMS; i++)
23643 {
23644 if(itemsbuf[i].family==itemtype)
23645 return i;
23646 }
23647
23648 return -1;
23649 }
23650
23651
23652 bool can_use_item(int32_t item_type, int32_t item)
23653 {
23654 //these are here to bypass compiler warnings about unused arguments
23655 item_type=item_type;
23656 item=item;
23657
23658 return true;
23659 }
23660
23661 bool has_item(int32_t item_type, int32_t it)
23662 {
23663 //these are here to bypass compiler warnings about unused arguments
23664 item_type=item_type;
23665 it=it;
23666
23667 return true;
23668 }
23669
23670 int32_t get_bmaps(int32_t si)
23671 {
23672 //these are here to bypass compiler warnings about unused arguments
23673 si=si;
23674
23675 return 255;
23676 }
23677
23678 bool no_subscreen()
23679 {
23680 return false;
23681 }
23682
23683 9 static void allocate_crap()
23684 {
23685 9 filepath=(char*)malloc(2048);
23686 9 datapath=(char*)malloc(2048);
23687 9 midipath=(char*)malloc(2048);
23688 9 imagepath=(char*)malloc(2048);
23689 9 tmusicpath=(char*)malloc(2048);
23690 9 last_timed_save=(char*)malloc(2048);
23691
23692
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(!filepath || !datapath || !imagepath || !midipath || !tmusicpath || !last_timed_save)
23693 {
23694 Z_error_fatal("Error: no memory for file paths!");
23695 }
23696
23697
23698 9 customtunes = (zctune*)malloc(sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23699 9 memset(customtunes, 0, sizeof(zctune)*MAXCUSTOMMIDIS_ZQ);
23700
23701
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; ++i)
23702 {
23703 2304 customtunes[i].data=NULL;
23704 2304 }
23705
23706
2/2
✓ Branch 0 taken 2268 times.
✓ Branch 1 taken 9 times.
2277 for(int32_t i=0; i<MAXCUSTOMTUNES; i++)
23707 {
23708 2268 midi_string[i+4]=customtunes[i].title;
23709 2268 screen_midi_string[i+5]=customtunes[i].title;
23710 2268 }
23711
23712
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<WAV_COUNT; i++)
23713 {
23714
1/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2304 if(sfx_string[i]!=NULL) delete sfx_string[i];
23715 2304 customsfxdata[i].data=NULL;
23716 2304 sfx_string[i] = new char[36];
23717 2304 memset(sfx_string[i], 0, 36);
23718 2304 }
23719
23720
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<MAXWPNS; i++)
23721 {
23722
1/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2304 if(weapon_string[i]!=NULL) delete weapon_string[i];
23723 2304 weapon_string[i] = new char[64];
23724 2304 memset(weapon_string[i], 0, 64);
23725 2304 }
23726
23727
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<MAXITEMS; i++)
23728 {
23729
1/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
2304 if(item_string[i]!=NULL) delete item_string[i];
23730 2304 item_string[i] = new char[64];
23731 2304 memset(item_string[i], 0, 64);
23732 2304 }
23733
23734
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<eMAXGUYS; i++)
23735 {
23736
1/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
4608 if(guy_string[i]!=NULL) delete guy_string[i];
23737 4608 guy_string[i] = new char[64];
23738 4608 memset(guy_string[i], 0, 64);
23739 4608 }
23740
23741
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
23742 {
23743
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 4608 times.
4608 delete ffscripts[i];
23744
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 ffscripts[i] = new script_data(ScriptType::FFC, i);
23745 4608 }
23746
23747
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
23748 {
23749
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete itemscripts[i];
23750
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 itemscripts[i] = new script_data(ScriptType::Item, i);
23751 2304 }
23752
23753
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
23754 {
23755
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete guyscripts[i];
23756
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 guyscripts[i] = new script_data(ScriptType::NPC, i);
23757 2304 }
23758
23759
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
23760 {
23761
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete screenscripts[i];
23762
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 screenscripts[i] = new script_data(ScriptType::Screen, i);
23763 2304 }
23764
23765
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 9 times.
81 for(int32_t i=0; i<NUMSCRIPTGLOBAL; i++)
23766 {
23767
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 72 times.
72 delete globalscripts[i];
23768
1/2
✓ Branch 0 taken 72 times.
✗ Branch 1 not taken.
72 globalscripts[i] = new script_data(ScriptType::Global, i);
23769 72 }
23770
23771
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 9 times.
54 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
23772 {
23773
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 delete playerscripts[i];
23774
1/2
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
45 playerscripts[i] = new script_data(ScriptType::Hero, i);
23775 45 }
23776
23777
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23778 {
23779
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete lwpnscripts[i];
23780
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 lwpnscripts[i] = new script_data(ScriptType::Lwpn, i);
23781 2304 }
23782
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
23783 {
23784
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2304 times.
2304 delete ewpnscripts[i];
23785
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 ewpnscripts[i] = new script_data(ScriptType::Ewpn, i);
23786 2304 }
23787
23788
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
23789 {
23790
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete dmapscripts[i];
23791
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 dmapscripts[i] = new script_data(ScriptType::DMap, i);
23792 2304 }
23793
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
23794 {
23795
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete itemspritescripts[i];
23796
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 itemspritescripts[i] = new script_data(ScriptType::ItemSprite, i);
23797 2304 }
23798
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
23799 {
23800
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 delete comboscripts[i];
23801
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 comboscripts[i] = new script_data(ScriptType::Combo, i);
23802 4608 }
23803
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<NUMSCRIPTSGENERIC; i++)
23804 {
23805
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 delete genericscripts[i];
23806
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 genericscripts[i] = new script_data(ScriptType::Generic, i);
23807 4608 }
23808
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
23809 {
23810
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2304 times.
2304 delete subscreenscripts[i];
23811
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 subscreenscripts[i] = new script_data(ScriptType::EngineSubscreen, i);
23812 2304 }
23813 9 }
23814
23815 // Removes the top layer encoding from a quest file. See open_quest_file.
23816 // This has zero impact on the contents of the quest file. There should be no way for this to
23817 // break anything.
23818 static void do_unencrypt_qst_command(const char* input_filename, const char* output_filename)
23819 {
23820 // If the file is already an unencrypted packfile, there's nothing to do.
23821 PACKFILE* pf_check = pack_fopen_password(input_filename, F_READ_PACKED, "");
23822 pack_fclose(pf_check);
23823 if (pf_check) return;
23824
23825 int32_t error;
23826 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23827 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE_PACKED, "");
23828 int c;
23829 while ((c = pack_getc(pf)) != EOF)
23830 {
23831 pack_putc(c, pf2);
23832 }
23833 pack_fclose(pf);
23834 pack_fclose(pf2);
23835 clear_quest_tmpfile();
23836 }
23837
23838 // This will remove the PACKFILE compression. Incidentally, it also removes the top encoding layer.
23839 static void do_uncompress_qst_command(const char* input_filename, const char* output_filename)
23840 {
23841 auto unencrypted_result = try_open_maybe_legacy_encoded_file(input_filename, ENC_STR, nullptr, QH_NEWIDSTR, QH_IDSTR);
23842 if (unencrypted_result.not_found)
23843 {
23844 printf("qst not found\n");
23845 zq_exit(1);
23846 }
23847 if (!unencrypted_result.compressed && !unencrypted_result.encrypted)
23848 {
23849 // If the file is already an uncompressed file, there's nothing to do but copy it.
23850 fs::copy(input_filename, output_filename);
23851 return;
23852 }
23853
23854 pack_fclose(unencrypted_result.decoded_pf);
23855
23856 int32_t error;
23857 PACKFILE* pf = open_quest_file(&error, input_filename, false);
23858 PACKFILE* pf2 = pack_fopen_password(output_filename, F_WRITE, "");
23859 int c;
23860 while ((c = pack_getc(pf)) != EOF)
23861 {
23862 pack_putc(c, pf2);
23863 }
23864 pack_fclose(pf);
23865 pack_fclose(pf2);
23866 clear_quest_tmpfile();
23867 }
23868
23869 // Copy a quest file by loading and resaving, exactly like if the user did it in the UI.
23870 // Note there could be changes introduced in the loading or saving functions. These are
23871 // typically for compatability, but could possibly be a source of bugs.
23872 2 static void do_copy_qst_command(const char* input_filename, const char* output_filename)
23873 {
23874 2 set_headless_mode();
23875
23876 // We need to init some stuff before loading a quest file will work.
23877 2 int fake_errno = 0;
23878 2 allegro_errno = &fake_errno;
23879 2 get_qst_buffers();
23880
23881 2 int ret = load_quest(input_filename, false);
23882
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 2 times.
2 if (ret)
23883 {
23884 zq_exit(ret);
23885 }
23886
23887 2 ret = save_quest(output_filename, false);
23888 2 zq_exit(ret);
23889 2 }
23890
23891 int32_t Awpn=-1, Bwpn=-1, Xwpn = -1, Ywpn = -1;
23892 63 sprite_list guys, items, Ewpns, Lwpns, chainlinks, decorations, portals;
23893 int32_t exittimer = 10000, exittimer2 = 100;
23894
23895 1 static bool partial_load_test(const char* test_dir)
23896 {
23897 1 int ret = load_quest("quests/Z1 Recreations/classic_1st.qst", false);
23898
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23899 {
23900 printf("failed to load classic_1st.qst: ret == %d\n", ret);
23901 return false;
23902 }
23903
23904 1 int cont = DMaps[0].cont;
23905
23906 // Skip same stuff as used in zq_tiles.cpp for grabbing tiles from a qst.
23907 byte skip_flags[4];
23908
2/2
✓ Branch 0 taken 26 times.
✓ Branch 1 taken 1 times.
27 for (int i=0; i<skip_max; ++i)
23909 26 set_bit(skip_flags,i,1);
23910 1 set_bit(skip_flags,skip_tiles,0);
23911 1 set_bit(skip_flags,skip_header,0);
23912 zquestheader tempheader;
23913 1 memset(&tempheader, 0, sizeof(zquestheader));
23914
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 auto ptux_path = fs::path(test_dir) / "quests/PTUX.qst";
23915
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
1 ret = loadquest(ptux_path.string().c_str(), &tempheader, &QMisc, customtunes, false, skip_flags);
23916
23917
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (ret)
23918 {
23919 printf("failed to load PTUX.qst: ret == %d\n", ret);
23920 return false;
23921 }
23922
23923
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (DMaps[0].cont != cont)
23924 {
23925 printf("unexpected modification: DMaps[0].cont == %d, should be %d\n", DMaps[0].cont, cont);
23926 return false;
23927 }
23928
23929 // TODO should run replay. Currently, resaving classic_1st.qst fails its replay (see test_save in test_zeditor.py)
23930
23931 1 return true;
23932 1 }
23933
23934 template <typename ...Params>
23935 [[noreturn]] void FatalConsole(const char *format, Params&&... params)
23936 {
23937 FFCore.ZScriptConsole(CConsoleLoggerEx::COLOR_RED|CConsoleLoggerEx::COLOR_INTENSITY|CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"");
23938 Z_error_fatal(format, std::forward<Params>(params)...);
23939 }
23940
23941 30 static BITMAP* load_asset_bmp(const char* path)
23942 {
23943 30 BITMAP* bmp = load_bmp(path, nullptr);
23944
1/2
✓ Branch 0 taken 30 times.
✗ Branch 1 not taken.
30 if (!bmp)
23945 Z_error_fatal("Failed to load required asset: %s\n", path);
23946 30 return bmp;
23947 }
23948
23949 6 static void load_asset_pal(PALETTE pal, const char* path)
23950 {
23951 6 BITMAP* bmp = load_bmp(path, pal);
23952
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!bmp)
23953 Z_error_fatal("Failed to load required asset: %s\n", path);
23954 6 }
23955
23956 6 static MIDI* load_asset_midi(const char* path)
23957 {
23958 6 MIDI* midi = load_midi(path);
23959
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!midi)
23960 Z_error_fatal("Failed to load required asset: %s\n", path);
23961 6 return midi;
23962 }
23963
23964 BITMAP* asset_icons_bmp;
23965 BITMAP* asset_engravings_bmp;
23966 BITMAP* asset_mouse_bmp;
23967 BITMAP* asset_select_bmp;
23968 BITMAP* asset_arrows_bmp;
23969 MIDI* asset_tunes_midi;
23970 PALETTE asset_pal;
23971
23972 6 static void load_assets()
23973 {
23974 6 asset_icons_bmp = load_asset_bmp("assets/editor/icons.bmp");
23975 6 asset_engravings_bmp = load_asset_bmp("assets/editor/engravings.bmp");
23976 6 asset_mouse_bmp = load_asset_bmp("assets/editor/mouse.bmp");
23977 6 asset_select_bmp = load_asset_bmp("assets/editor/select.bmp");
23978 6 asset_arrows_bmp = load_asset_bmp("assets/editor/arrows.bmp");
23979 6 asset_tunes_midi = load_asset_midi("assets/editor/tunes.mid");
23980 6 load_asset_pal(asset_pal, "assets/editor/pal.bmp");
23981 6 }
23982
23983 static bool application_has_loaded;
23984
23985 6 int32_t main(int32_t argc,char **argv)
23986 {
23987 6 int test_zc_arg = used_switch(argc, argv, "-test-zc");
23988
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if (test_zc_arg > 0)
23989 1 set_headless_mode();
23990
23991 6 zalleg_setup_allegro(App::zquest, argc, argv);
23992 6 allocate_crap();
23993
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 set_should_zprint_cb([]() {
23994 return get_qr(qr_SCRIPTERRLOG) || DEVLEVEL > 0;
23995 });
23996
23997 6 int package_arg = used_switch(argc, argv, "-package");
23998
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (package_arg > 0)
23999 {
24000 if (package_arg + 3 > argc)
24001 {
24002 printf("%d\n", argc);
24003 printf("expected -package <game.qst> <package name>\n");
24004 zq_exit(1);
24005 }
24006
24007 const char* input_filename = argv[package_arg + 1];
24008 const char* package_name = argv[package_arg + 2];
24009 if (auto error = package_create(input_filename, package_name))
24010 Z_error_fatal("%s\n", error->c_str());
24011 zq_exit(0);
24012 }
24013
24014 6 int copy_qst_arg = used_switch(argc, argv, "-copy-qst");
24015
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (copy_qst_arg > 0)
24016 {
24017
1/2
✓ Branch 0 taken 2 times.
✗ Branch 1 not taken.
2 if (copy_qst_arg + 3 > argc)
24018 {
24019 printf("%d\n", argc);
24020 printf("expected -copy-qst <input> <output>\n");
24021 zq_exit(1);
24022 }
24023
24024 2 const char* input_filename = argv[copy_qst_arg + 1];
24025 2 const char* output_filename = argv[copy_qst_arg + 2];
24026 2 do_copy_qst_command(input_filename, output_filename);
24027 2 }
24028
24029 6 Z_title("%s, %s",ZQ_EDITOR_NAME, getVersionString());
24030
24031
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!get_qst_buffers())
24032 {
24033 Z_error_fatal("Error");
24034 }
24035
24036 6 undocombobuf.clear();
24037 6 undocombobuf.resize(MAXCOMBOS);
24038
24039
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if((newundotilebuf=(tiledata*)malloc(NEWMAXTILES*sizeof(tiledata)))==NULL)
24040 {
24041 Z_error_fatal("Error: no memory for tile undo buffer!");
24042 }
24043
24044 6 memset(newundotilebuf, 0, NEWMAXTILES*sizeof(tiledata));
24045
24046 6 Z_message("Resetting new tile buffer...");
24047 6 newtilebuf = (tiledata*)malloc(NEWMAXTILES*sizeof(tiledata));
24048
24049
2/2
✓ Branch 0 taken 1501500 times.
✓ Branch 1 taken 6 times.
1501506 for(int32_t j=0; j<NEWMAXTILES; j++)
24050 1501500 newtilebuf[j].data=NULL;
24051
24052 6 Z_message("OK\n");
24053
24054 6 zc_srand(time(0));
24055
24056
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if (test_zc_arg > 0)
24057 {
24058 1 set_headless_mode();
24059
24060
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (test_zc_arg + 1 > argc)
24061 {
24062 printf("%d\n", argc);
24063 printf("expected -test-zc <path to test dir>\n");
24064 zq_exit(1);
24065 }
24066
24067 1 const char* test_dir = argv[test_zc_arg + 1];
24068
24069 // We need to init some stuff before loading a quest file will work.
24070 1 int fake_errno = 0;
24071 1 allegro_errno = &fake_errno;
24072 1 get_qst_buffers();
24073
24074 1 bool success = true;
24075
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!partial_load_test(test_dir))
24076 {
24077 success = false;
24078 printf("partial_load_test failed\n");
24079 }
24080
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 1 times.
1 if (success)
24081 1 printf("all tests passed\n");
24082 1 zq_exit(success ? 0 : 1);
24083 1 }
24084
24085 6 int unencrypt_qst_arg = used_switch(argc, argv, "-unencrypt-qst");
24086
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (unencrypt_qst_arg > 0)
24087 {
24088 if (unencrypt_qst_arg + 3 > argc)
24089 {
24090 printf("%d\n", argc);
24091 printf("expected -unencrypt-qst <input> <output>\n");
24092 zq_exit(1);
24093 }
24094
24095 const char* input_filename = argv[unencrypt_qst_arg + 1];
24096 const char* output_filename = argv[unencrypt_qst_arg + 2];
24097 do_unencrypt_qst_command(input_filename, output_filename);
24098 zq_exit(0);
24099 }
24100
24101 6 int uncompress_qst_arg = used_switch(argc, argv, "-uncompress-qst");
24102
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if (uncompress_qst_arg > 0)
24103 {
24104 if (uncompress_qst_arg + 3 > argc)
24105 {
24106 printf("%d\n", argc);
24107 printf("expected -uncompress-qst <input> <output>\n");
24108 zq_exit(1);
24109 }
24110
24111 const char* input_filename = argv[uncompress_qst_arg + 1];
24112 const char* output_filename = argv[uncompress_qst_arg + 2];
24113 do_uncompress_qst_command(input_filename, output_filename);
24114 zq_exit(0);
24115 }
24116
24117 6 three_finger_flag=false;
24118
24119 #ifndef __EMSCRIPTEN__
24120
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(zc_get_config("zquest","open_debug_console",0))
24121 initConsole();
24122 #endif
24123
24124 LOCK_VARIABLE(lastfps);
24125
24126 LOCK_VARIABLE(framecnt);
24127 LOCK_FUNCTION(fps_callback);
24128
24129
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(install_int_ex(fps_callback,SECS_TO_TIMER(1)))
24130 {
24131 Z_error_fatal("couldn't allocate timer");
24132 }
24133
24134
24135 LOCK_VARIABLE(dclick_status);
24136 LOCK_VARIABLE(dclick_time);
24137 6 lock_dclick_function();
24138 6 install_int(dclick_check, 20);
24139
24140 6 set_gfx_mode(GFX_TEXT,80,50,0,0);
24141
24142 6 load_assets();
24143
24144 6 Z_message("OK\n");
24145
24146
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 helpstr = util::read_text_file("docs/zquest.txt");
24147
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 zstringshelpstr = util::read_text_file("docs/zstrings.txt");
24148
24149 // loading data files...
24150
24151 6 filepath[0]=temppath[0]=0;
24152
24153 6 const char *default_path="";
24154
24155 6 strcpy(datapath,zc_get_config("zquest",data_path_name,default_path));
24156 6 strcpy(midipath,zc_get_config("zquest",midi_path_name,default_path));
24157 6 strcpy(imagepath,zc_get_config("zquest",image_path_name,default_path));
24158 6 strcpy(tmusicpath,zc_get_config("zquest",tmusic_path_name,default_path));
24159 6 chop_path(datapath);
24160 6 chop_path(midipath);
24161 6 chop_path(imagepath);
24162 6 chop_path(tmusicpath);
24163
24164 6 DisableLPalShortcuts = zc_get_config("zquest","dis_lpal_shortcut",1);
24165 6 DisableCompileConsole = zc_get_config("zquest","internal_compile_console",0);
24166 6 MouseScroll = zc_get_config("zquest","mouse_scroll",0);
24167 6 WarnOnInitChanged = zc_get_config("zquest","warn_initscript_changes",1);
24168 6 MMapCursorStyle = zc_get_config("zquest","cursorblink_style",1);
24169 6 LayerDitherBG = zc_get_config("zquest", "layer_dither_bg", -1);
24170 6 LayerDitherSz = zc_get_config("zquest", "layer_dither_sz", 3);
24171 6 InvalidBG = zc_get_config("zquest", "invalid_bg", 0);
24172 6 TileProtection = zc_get_config("zquest","tile_protection",1);
24173 6 ComboProtection = zc_get_config("zquest","combo_protection",TileProtection);
24174 6 ShowGrid = zc_get_config("zquest","show_grid",0);
24175 6 ShowCurScreenOutline = zc_get_config("zquest","show_current_screen_outline",1);
24176 6 ShowScreenGrid = zc_get_config("zquest","show_screen_grid",0);
24177 6 GridColor = zc_get_config("zquest","grid_color",15);
24178 6 CmbCursorCol = zc_get_config("zquest","combo_cursor_color",15);
24179 6 TilePgCursorCol = zc_get_config("zquest","tpage_cursor_color",15);
24180 6 CmbPgCursorCol = zc_get_config("zquest","cpage_cursor_color",15);
24181 6 TTipHLCol = zc_get_config("zquest","ttip_hl_color",13);
24182 6 CheckerCol1 = zc_get_config("zquest","checker_color_1",7);
24183 6 CheckerCol2 = zc_get_config("zquest","checker_color_2",8);
24184 6 SnapshotFormat = zc_get_config("zquest","snapshot_format",3);
24185 6 SnapshotScale = zc_get_config("zquest","snapshot_scale",2);
24186 6 SavePaths = zc_get_config("zquest","save_paths",1);
24187 6 CycleOn = zc_get_config("zquest","cycle_on",1);
24188 6 ShowFPS = zc_get_config("zquest","showfps",0)!=0;
24189 6 SaveDragResize = zc_get_config("zquest","save_drag_resize",0)!=0;
24190 6 DragAspect = zc_get_config("zquest","drag_aspect",0)!=0;
24191 6 SaveWinPos = zc_get_config("zquest","save_window_position",0)!=0;
24192 6 ComboBrush = zc_get_config("zquest","combo_brush",0);
24193 6 FloatBrush = zc_get_config("zquest","float_brush",0);
24194 6 AutoBrush = zc_get_config("zquest","autobrush",1);
24195 6 LinkedScroll = zc_get_config("zquest","linked_comboscroll",0);
24196 6 allowHideMouse = zc_get_config("ZQ_GUI","allowHideMouse",0);
24197 6 ShowFavoriteComboModes = zc_get_config("ZQ_GUI","show_fav_combo_modes",1);
24198 6 NoHighlightLayer0 = zc_get_config("zquest","no_highlight_layer0",0);
24199 6 RulesetDialog = zc_get_config("zquest","rulesetdialog",1);
24200 6 EnableTooltips = zc_get_config("zquest","enable_tooltips",1);
24201 6 TooltipsHighlight = zc_get_config("zquest","ttip_highlight",1);
24202 6 tooltip_maxtimer = vbound(zc_get_config("zquest","ttip_timer",30),0,60*60);
24203 6 ShowFFScripts = zc_get_config("zquest","showffscripts",1);
24204 6 ShowSquares = zc_get_config("zquest","showsquares",1);
24205 6 ShowFFCs = zc_get_config("zquest","showffcs",0);
24206 6 ShowInfo = zc_get_config("zquest","showinfo",1);
24207 6 skipLayerWarning = zc_get_config("zquest","skip_layer_warning",0);
24208 6 numericalFlags = zc_get_config("zquest","numerical_flags",0);
24209 6 ViewLayer2BG = zc_get_config("zquest","layer2_bg",0);
24210 6 ViewLayer3BG = zc_get_config("zquest","layer3_bg",0);
24211 6 ActiveLayerHighlight = zc_get_config("zquest","hl_active_lyr",0);
24212 6 DragCenterOfSquares = zc_get_config("zquest","drag_squares_from_center",0);
24213
24214 6 OpenLastQuest = zc_get_config("zquest","open_last_quest",0);
24215 6 ShowMisalignments = zc_get_config("zquest","show_misalignments",0);
24216 6 AnimationOn = zc_get_config("zquest","animation_on",1);
24217 6 AutoBackupRetention = zc_get_config("zquest","auto_backup_retention",2);
24218 6 AutoSaveInterval = zc_get_config("zquest","auto_save_interval",6);
24219 6 AutoSaveRetention = zc_get_config("zquest","auto_save_retention",2);
24220 6 UncompressedAutoSaves = zc_get_config("zquest","uncompressed_auto_saves",1);
24221 6 OverwriteProtection = zc_get_config("zquest","overwrite_prevention",0)!=0;
24222 6 ImportMapBias = zc_get_config("zquest","import_map_bias",0);
24223
24224 6 KeyboardRepeatDelay = zc_get_config("zquest","keyboard_repeat_delay",300);
24225 6 KeyboardRepeatRate = zc_get_config("zquest","keyboard_repeat_rate",80);
24226
24227 // Frameskip = zc_get_config("zquest","frameskip",0); //todo: this is not actually supported yet.
24228 6 RequestedFPS = zc_get_config("zquest","fps",60);
24229
24230 // Autofill for Combo Page, Tile Page
24231 6 PreFillTileEditorPage = zc_get_config("zquest","PreFillTileEditorPage",0);
24232 6 PreFillComboEditorPage = zc_get_config("zquest","PreFillComboEditorPage",0);
24233
24234 6 pixeldb = zc_get_config("ZQ_GUI","bottom_8_pixels",0);
24235 6 infobg = zc_get_config("ZQ_GUI","info_text_bg",0);
24236
24237 6 large_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_large",0);
24238 6 compact_merged_combopane = zc_get_config("ZQ_GUI","merge_cpane_compact",1);
24239
24240 6 compact_square_panels = zc_get_config("ZQ_GUI","square_panels_compact",0);
24241
24242 6 large_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_large",0);
24243 6 compact_zoomed_fav = zc_get_config("ZQ_GUI","zoom_fav_compact",1);
24244 6 large_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_large",1);
24245 6 compact_zoomed_cmd = zc_get_config("ZQ_GUI","zoom_cmd_compact",1);
24246
24247
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(zc_get_config("gui","disable_window_resizing",0))
24248 all_set_resize_flag(false);
24249
24250 6 load_hotkeys();
24251
24252 #ifdef _WIN32
24253 zqUseWin32Proc = zc_get_config("zquest","zq_win_proc_fix",0);
24254
24255 #endif
24256
24257
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!render_timer_start())
24258 {
24259 Z_error_fatal("couldn't allocate timer");
24260 }
24261
24262 6 byte layermask = zc_get_config("zquest","layer_mask",0x7F);
24263 6 int32_t usefullscreen = zc_get_config("zquest","fullscreen",0);
24264 6 tempmode = (usefullscreen == 0 ? GFX_AUTODETECT_WINDOWED : GFX_AUTODETECT_FULLSCREEN);
24265
24266
2/2
✓ Branch 0 taken 42 times.
✓ Branch 1 taken 6 times.
48 for(int32_t x=0; x<7; x++)
24267 {
24268 42 LayerMaskInt[x]=get_bit(&layermask,x);
24269 42 }
24270
24271 6 DuplicateAction[0] = zc_get_config("zquest","normal_duplicate_action",2);
24272 6 DuplicateAction[1] = zc_get_config("zquest","horizontal_duplicate_action",0);
24273 6 DuplicateAction[2] = zc_get_config("zquest","vertical_duplicate_action",0);
24274 6 DuplicateAction[3] = zc_get_config("zquest","both_duplicate_action",0);
24275 6 LeechUpdate = zc_get_config("zquest","leech_update",500);
24276 6 LeechUpdateTiles = zc_get_config("zquest","leech_update_tiles",1);
24277 6 OnlyCheckNewTilesForDuplicates = zc_get_config("zquest","only_check_new_tiles_for_duplicates",0);
24278 //gui_colorset = zc_get_config("zquest","gui_colorset",0);
24279
24280 6 strcpy(last_timed_save,zc_get_config("zquest","last_timed_save",""));
24281
24282 6 midi_volume = zc_get_config("zquest", "midi", 255);
24283
24284 6 abc_patternmatch = zc_get_config("zquest", "lister_pattern_matching", 1);
24285 6 NoScreenPreview = zc_get_config("zquest", "no_preview", 0);
24286
24287 6 monochrome_console = zc_get_config("CONSOLE","monochrome_debuggers",0)?1:0;
24288
24289 6 try_recovering_missing_scripts = 0;//zc_get_config("Compiler", "try_recovering_missing_scripts",0);
24290 //We need to remove all of the zeldadx refs to the config file for zquest.
24291
24292 6 set_keyboard_rate(KeyboardRepeatDelay,KeyboardRepeatRate);
24293
24294 6 is_compact = zc_get_config("ZQ_GUI","compact_mode",1);
24295 6 mapscreenbmp = nullptr;
24296 6 brushbmp = nullptr;
24297 6 brushscreen = nullptr;
24298 6 screen2 = nullptr;
24299 6 tmp_scr = nullptr;
24300 6 menu1 = nullptr;
24301 6 menu3 = nullptr;
24302
24303
2/2
✓ Branch 0 taken 7560 times.
✓ Branch 1 taken 6 times.
7566 for(int32_t i=0; i<MAXFAVORITECOMBOS; ++i)
24304 {
24305 7560 favorite_combos[i]=-1;
24306 7560 pool_combos[i].clear();
24307 7560 }
24308 6 FavoriteComboPage = 0;
24309 6 pool_dirty = true;
24310
24311
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(used_switch(argc,argv,"-d"))
24312 {
24313 set_debug(!strcmp(zquestpwd,zc_get_config("zquest","debug_this","")));
24314 }
24315
24316 6 zcmusic_init();
24317 6 zcmixer = zcmixer_create();
24318 2792 install_int_ex([](){ zcmusic_poll(); }, MSEC_TO_TIMER(25));
24319
24320 6 set_color_depth(8);
24321
24322 6 set_close_button_callback((void (*)()) hit_close_button);
24323
24324
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(used_switch(argc,argv,"-fullscreen"))
24325 {
24326 tempmode = GFX_AUTODETECT_FULLSCREEN;
24327 }
24328
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 else if(used_switch(argc,argv,"-windowed"))
24329 {
24330 tempmode=GFX_AUTODETECT_WINDOWED;
24331 }
24332
24333 6 zq_screen_w = LARGE_W;
24334 6 zq_screen_h = LARGE_H;
24335 6 window_width = zc_get_config("zquest","window_width",-1);
24336 6 window_height = zc_get_config("zquest","window_height",-1);
24337 6 auto [w, h] = zc_get_default_display_size(LARGE_W, LARGE_H, window_width, window_height);
24338
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 int32_t videofail = is_headless() ? 0 : (set_gfx_mode(tempmode,w,h,zq_screen_w,zq_screen_h));
24339
24340 //extra block here is intentional
24341
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(videofail!=0)
24342 {
24343 quit_game();
24344 allegro_exit();
24345 }
24346
24347 6 zalleg_create_window();
24348 6 Z_message("gfx mode set at -%d %dbpp %d x %d \n",
24349 6 tempmode, get_color_depth(), zq_screen_w, zq_screen_h);
24350
24351 6 set_window_title("ZC Editor");
24352
24353 6 load_size_poses();
24354
24355
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!is_headless())
24356 {
24357 // Just in case.
24358 while (!all_get_display()) {
24359 al_rest(1);
24360 }
24361
24362 al_resize_display(all_get_display(), w, h);
24363 }
24364
24365
24366 #ifndef __EMSCRIPTEN__
24367
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
✗ Branch 3 not taken.
6 if (!all_get_fullscreen_flag() && !is_headless()) {
24368 al_resize_display(all_get_display(), w, h);
24369
24370 int window_w = al_get_display_width(all_get_display());
24371 int window_h = al_get_display_height(all_get_display());
24372
24373 int new_x = zc_get_config("zquest","window_x",0);
24374 int new_y = zc_get_config("zquest","window_y",0);
24375 if(zc_get_config("zquest","save_window_position",0) && (new_x || new_y))
24376 {
24377 //load saved position
24378 //already stored in new_x/new_y
24379 }
24380 else
24381 {
24382 //Get default position
24383 ALLEGRO_MONITOR_INFO info;
24384 al_get_monitor_info(0, &info);
24385
24386 int mw = (info.x2 - info.x1);
24387 int mh = (info.y2 - info.y1);
24388 new_x = mw / 2 - window_w / 2;
24389 new_y = mh / 2 - window_h / 2;
24390 //Don't spawn the window too far down (taskbar?)
24391 if(new_y + window_h > mh - 72)
24392 new_y = mh-72-window_h;
24393 }
24394 #ifdef ALLEGRO_MACOSX
24395 if (zc_get_config("zquest","save_window_position",0))
24396 al_set_window_position(all_get_display(), new_x, new_y);
24397 #else
24398 al_set_window_position(all_get_display(), new_x, new_y);
24399 #endif
24400 }
24401 #endif
24402
24403 6 position_mouse(zq_screen_w/2,zq_screen_h/2);
24404
24405 6 dmapbmp_small = create_bitmap_ex(8,65,33);
24406 6 dmapbmp_large = create_bitmap_ex(8,177,81);
24407
24408
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!screen2 || !tmp_scr || !menu1 || !menu3 || !dmapbmp_large || !dmapbmp_large || !brushbmp || !brushscreen)// || !brushshadowbmp )
24409 {
24410 Z_error_fatal("Failed to create system bitmaps!\n");
24411 return 1;
24412 }
24413
24414 6 int quick_assign_arg = used_switch(argc, argv, "-quick-assign");
24415
2/2
✓ Branch 0 taken 2 times.
✓ Branch 1 taken 4 times.
6 if (quick_assign_arg > 0)
24416 {
24417 4 is_zq_replay_test = true;
24418 4 set_headless_mode();
24419
24420 4 int load_ret = load_quest(argv[quick_assign_arg + 1], false);
24421 4 bool success = load_ret == qe_OK;
24422
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!success)
24423 {
24424 printf("Failed to load quest: %d\n", load_ret);
24425 zq_exit(1);
24426 }
24427
24428 4 success = do_compile_and_slots(1, false);
24429
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!success)
24430 {
24431 printf("Failed to compile\n");
24432 zq_exit(1);
24433 }
24434
24435 4 success = save_quest(argv[quick_assign_arg + 1], false) == 0;
24436
1/2
✓ Branch 0 taken 4 times.
✗ Branch 1 not taken.
4 if (!success)
24437 {
24438 printf("Failed to save quest\n");
24439 zq_exit(1);
24440 }
24441
24442 4 zq_exit(0);
24443 4 }
24444
24445 6 int smart_assign_arg = used_switch(argc, argv, "-smart-assign");
24446
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (smart_assign_arg > 0)
24447 {
24448 is_zq_replay_test = true;
24449 set_headless_mode();
24450
24451 int load_ret = load_quest(argv[smart_assign_arg + 1], false);
24452 bool success = load_ret == qe_OK;
24453 if (!success)
24454 {
24455 printf("Failed to load quest: %d\n", load_ret);
24456 zq_exit(1);
24457 }
24458
24459 success = do_compile_and_slots(2, false);
24460 if (!success)
24461 {
24462 printf("Failed to compile\n");
24463 zq_exit(1);
24464 }
24465
24466 success = save_quest(argv[smart_assign_arg + 1], false) == 0;
24467 if (!success)
24468 {
24469 printf("Failed to save quest\n");
24470 zq_exit(1);
24471 }
24472
24473 zq_exit(0);
24474 }
24475
24476 6 int export_strings_arg = used_switch(argc, argv, "-export-strings");
24477
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if (export_strings_arg > 0)
24478 {
24479
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (export_strings_arg + 3 > argc)
24480 {
24481 printf("%d\n", argc);
24482 printf("expected -export-strings input.qst output.tsv\n");
24483 zq_exit(1);
24484 }
24485
24486 1 is_zq_replay_test = true;
24487 1 set_headless_mode();
24488
24489 1 int load_ret = load_quest(argv[export_strings_arg + 1], false);
24490 1 bool success = load_ret == qe_OK;
24491
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
24492 {
24493 printf("Failed to load quest: %d\n", load_ret);
24494 zq_exit(1);
24495 }
24496
24497 1 success = save_strings_tsv(argv[export_strings_arg + 2]);
24498
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (!success)
24499 {
24500 printf("Failed to export strings\n");
24501 zq_exit(1);
24502 }
24503
24504 1 zq_exit(0);
24505 1 }
24506
24507
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!is_headless())
24508 {
24509 zc_set_palette(asset_pal);
24510 get_palette(RAMpal);
24511 load_colorset(gui_colorset);
24512 zc_set_palette(RAMpal);
24513 clear_to_color(screen,vc(0));
24514 }
24515
24516 6 zScript = string();
24517 6 strcpy(zScriptBytes, "0 Bytes in Buffer");
24518
2/2
✓ Branch 0 taken 12 times.
✓ Branch 1 taken 6 times.
18 for(int32_t i=0; i<MOUSE_BMP_MAX; i++)
24519 {
24520
2/2
✓ Branch 0 taken 48 times.
✓ Branch 1 taken 12 times.
60 for(int32_t j=0; j<4; j++)
24521 {
24522 48 mouse_bmp[i][j] = NULL;
24523 48 mouse_bmp_1x[i][j] = NULL;
24524 48 }
24525 12 }
24526 6 load_mice();
24527 6 gui_mouse_focus=0;
24528 6 MouseSprite::set(ZQM_NORMAL);
24529 6 render_zq(); // Ensure the rendering bitmaps are setup.
24530
24531 #ifdef __EMSCRIPTEN__
24532 em_mark_ready_status();
24533 #endif
24534
24535 6 load_icons();
24536
24537 6 bool load_last_timed_save=false;
24538
24539 6 load_recent_quests();
24540 6 refresh_recent_menu();
24541 //clearConsole();
24542
1/4
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
✗ Branch 2 not taken.
✗ Branch 3 not taken.
6 if((last_timed_save[0]!=0)&&(exists(last_timed_save)))
24543 {
24544 if(jwin_alert("ZQuest","It appears that ZQuest crashed last time.","Would you like to load the last timed save?",NULL,"&Yes","&No",'y','n',get_zc_font(font_lfont))==1)
24545 {
24546 int32_t ret = load_quest(last_timed_save);
24547
24548 if(ret == qe_OK)
24549 {
24550 strcpy(filepath,last_timed_save);
24551 load_last_timed_save=true;
24552 saved=false;
24553 }
24554 else
24555 {
24556 jwin_alert("Error","Unable to reload the last timed save.",NULL,NULL,"OK",NULL,13,27,get_zc_font(font_lfont));
24557 }
24558 }
24559 }
24560
24561
2/2
✓ Branch 0 taken 5 times.
✓ Branch 1 taken 1 times.
6 if(!load_last_timed_save)
24562 {
24563 1 strcpy(filepath,zc_get_config("zquest",last_quest_name,""));
24564
24565
2/4
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
1 if(argc>1 && argv[1][0]!='-')
24566 {
24567 int32_t ret = load_quest(argv[1]);
24568
24569 if(ret == qe_OK)
24570 {
24571 first_save=true;
24572 strcpy(filepath,argv[1]);
24573 refresh(rALL);
24574 }
24575 }
24576
2/8
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 1 times.
✗ Branch 4 not taken.
✗ Branch 5 not taken.
✗ Branch 6 not taken.
✗ Branch 7 not taken.
1 else if(OpenLastQuest&&filepath[0]&&exists(filepath)&&!used_switch(argc,argv,"-new"))
24577 {
24578 int32_t ret = load_quest(filepath);
24579
24580 if(ret == qe_OK)
24581 {
24582 first_save=true;
24583 refresh(rALL);
24584 }
24585 else
24586 {
24587 filepath[0]=temppath[0]=0;
24588 first_save=false;
24589 }
24590 }
24591 else
24592 {
24593
1/2
✓ Branch 0 taken 1 times.
✗ Branch 1 not taken.
1 if (onNew() == D_CLOSE)
24594 exit(0);
24595
24596 //otherwise the blank quest gets the name of the last loaded quest... not good! -DD
24597 1 filepath[0]=temppath[0]=0;
24598 1 first_save=false;
24599 }
24600 1 }
24601
24602
2/2
✓ Branch 0 taken 1 times.
✓ Branch 1 taken 5 times.
6 if(used_switch(argc,argv,"-q"))
24603 {
24604 1 Z_message("-q switch used, quitting program.\n");
24605 1 zq_exit(0);
24606 1 }
24607
24608
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 for(int32_t x=0; x<MAXITEMS; x++)
24609 {
24610 lens_hint_item[x][0]=0;
24611 lens_hint_item[x][1]=0;
24612 }
24613
24614
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 for(int32_t x=0; x<MAXWPNS; x++)
24615 {
24616 lens_hint_weapon[x][0]=0;
24617 lens_hint_weapon[x][1]=0;
24618 }
24619
24620 6 load_selections();
24621 6 load_arrows();
24622 6 clear_to_color(menu1,vc(0));
24623 6 DIALOG_PLAYER *player2=init_dialog(dialogs,-1);
24624
24625 6 get_palette(RAMpal);
24626
24627 6 rgb_map = &zq_rgb_table;
24628
24629 #ifdef __EMSCRIPTEN__
24630 {
24631 int qs_map = EM_ASM_INT({
24632 return new URL(location.href).searchParams.get('map') ?? -1;
24633 });
24634 int qs_screen = EM_ASM_INT({
24635 return new URL(location.href).searchParams.get('screen') ?? -1;
24636 });
24637 if (qs_map != -1 && qs_screen != -1) {
24638 Map.setCurrMap(qs_map);
24639 Map.setCurrScr(qs_screen);
24640 }
24641 }
24642 #endif
24643
24644 // setup_combo_animations();
24645 6 pause_refresh = false;
24646 6 refresh_pal();
24647 6 refresh(rALL);
24648
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 for(int q = 0; q < brush_width_menu.size(); ++q)
24649 brush_width_menu.at(q)->select(q==0);
24650
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 for(int q = 0; q < brush_height_menu.size(); ++q)
24651 brush_height_menu.at(q)->select(q==0);
24652 6 set_filltype(1);
24653
24654 6 rebuild_trans_table();
24655
24656
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if (!is_headless())
24657 {
24658 set_display_switch_mode(SWITCH_BACKGROUND);
24659 set_display_switch_callback(SWITCH_OUT, switch_out);
24660 set_display_switch_callback(SWITCH_IN, switch_in);
24661 }
24662
24663
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(!update_dialog(player2))
24664 exiting_program = true;
24665 //clear_keybuf();
24666 6 media_menu.disable_uid(MENUID_MEDIA_CHANGETRACK, true);
24667 6 disable_hotkey(ZQKEY_CHANGE_TRACK, true);
24668
24669 6 fix_drawing_mode_menu();
24670
24671
24672 #ifdef _WIN32
24673
24674 if(zqUseWin32Proc != FALSE)
24675 {
24676 al_trace("Config file warning: \"zq_win_proc_fix\" enabled switch found. This can cause crashes on some computers.\n");
24677 win32data.zqSetDefaultThreadPriority(0);
24678 win32data.zqSetCustomCallbackProc(al_get_win_window_handle(all_get_display()));
24679 }
24680
24681 #endif
24682
24683 6 time(&auto_save_time_start);
24684
24685 6 FFCore.init();
24686 6 ZQincludePaths = FFCore.includePaths;
24687
24688 6 Map.setCopyFFC(-1); //Do not have an initial ffc on the clipboard.
24689 6 brush_menu.select_uid(MENUID_BRUSH_AUTOBRUSH, AutoBrush);
24690 6 brush_menu.disable_uid(MENUID_BRUSH_WIDTH, AutoBrush);
24691 6 brush_menu.disable_uid(MENUID_BRUSH_HEIGHT, AutoBrush);
24692 6 brush_menu.select_uid(MENUID_BRUSH_COMBOBRUSH, ComboBrush);
24693 6 brush_menu.select_uid(MENUID_BRUSH_FLOATBRUSH, FloatBrush);
24694
24695 6 init_ffpos();
24696
24697 6 call_foo_dlg();
24698
24699 6 application_has_loaded = true;
24700
24701
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 while(!exiting_program)
24702 {
24703 #ifdef _WIN32
24704 if(zqUseWin32Proc != FALSE)
24705 win32data.Update(Frameskip); //experimental win32 fixes
24706 #endif
24707 check_autosave();
24708 ++alignment_arrow_timer;
24709
24710 if(alignment_arrow_timer>63)
24711 {
24712 alignment_arrow_timer=0;
24713 }
24714 ++frame;
24715
24716 file_menu.disable_uid(MENUID_FILE_SAVE, saved||disable_saving||OverwriteProtection);
24717 file_menu.disable_uid(MENUID_FILE_REVERT, saved||disable_saving||OverwriteProtection);
24718 file_menu.disable_uid(MENUID_FILE_SAVEAS, disable_saving);
24719
24720 fixtools_menu.disable_uid(MENUID_FIXTOOL_OLDSTRING,
24721 !(get_qr(qr_OLD_STRING_EDITOR_MARGINS)
24722 ||get_qr(qr_STRING_FRAME_OLD_WIDTH_HEIGHT)));
24723
24724 edit_menu.disable_uid(MENUID_EDIT_UNDO, !Map.CanUndo());
24725 edit_menu.disable_uid(MENUID_EDIT_REDO, !Map.CanRedo());
24726
24727 bool canpaste = Map.CanPaste();
24728 edit_menu.disable_uid(MENUID_EDIT_PASTE, !canpaste);
24729 edit_menu.disable_uid(MENUID_EDIT_PASTEALL, !canpaste);
24730 edit_menu.disable_uid(MENUID_EDIT_ADVPASTE, !canpaste);
24731 edit_menu.disable_uid(MENUID_EDIT_SPECPASTE, !canpaste);
24732 rc_menu_screen.disable_uid(MENUID_RCSCREEN_PASTE, !canpaste);
24733 rc_menu_screen.disable_uid(MENUID_RCSCREEN_ADVPASTE, !canpaste);
24734 rc_menu_screen.disable_uid(MENUID_RCSCREEN_SPECPASTE, !canpaste);
24735 for(MenuItem& mit : paste_menu.inner())
24736 mit.disable(!canpaste);
24737 for(MenuItem& mit : paste_item_menu.inner())
24738 mit.disable(!canpaste);
24739
24740 edit_menu.disable_uid(MENUID_EDIT_COPY, !(Map.CurrScr()->valid&mVALID));
24741 edit_menu.disable_uid(MENUID_EDIT_DELETE, !(Map.CurrScr()->valid&mVALID));
24742
24743 // Are some things selected?
24744 view_menu.select_uid(MENUID_VIEW_WALKABILITY, Flags&cWALK);
24745 view_menu.select_uid(MENUID_VIEW_FLAGS, Flags&cFLAGS);
24746 view_menu.select_uid(MENUID_VIEW_CSET, Flags&cCSET);
24747 view_menu.select_uid(MENUID_VIEW_TYPES, Flags&cCTYPE);
24748 view_menu.select_uid(MENUID_VIEW_INFO, ShowInfo);
24749 view_menu.select_uid(MENUID_VIEW_SQUARES, ShowSquares);
24750 view_menu.select_uid(MENUID_VIEW_FFCS, ShowFFCs);
24751 view_menu.select_uid(MENUID_VIEW_SCRIPTNAMES, ShowFFScripts);
24752 view_menu.select_uid(MENUID_VIEW_GRID, ShowGrid);
24753 view_menu.select_uid(MENUID_VIEW_SCREENGRID, ShowScreenGrid);
24754 view_menu.select_uid(MENUID_VIEW_CURSCROUTLINE, ShowCurScreenOutline);
24755 view_menu.select_uid(MENUID_VIEW_DARKNESS, get_qr(qr_NEW_DARKROOM) && (Flags&cNEWDARK));
24756 view_menu.select_uid(MENUID_VIEW_L2BG, ViewLayer2BG);
24757 view_menu.select_uid(MENUID_VIEW_L3BG, ViewLayer3BG);
24758 view_menu.select_uid(MENUID_VIEW_LAYERHIGHLIGHT, ActiveLayerHighlight);
24759
24760 maps_menu.disable_uid(MENUID_MAPS_NEXT, !map_count || Map.getCurrMap() >= map_count);
24761 maps_menu.disable_uid(MENUID_MAPS_PREV, Map.getCurrMap()<=0);
24762
24763 etc_menu.disable_uid(MENUID_ETC_VIDMODE, isFullScreen()==1);
24764 etc_menu.select_uid(MENUID_ETC_FULLSCREEN, isFullScreen()==1);
24765
24766 if(!update_dialog(player2))
24767 exiting_program = true;
24768
24769 //clear_keybuf();
24770 handle_close_btn_quit();
24771 }
24772
24773 6 zq_exit(0);
24774 6 return 0;
24775 }
24776 END_OF_MAIN()
24777
24778 9 void zq_exit(int code)
24779 {
24780 9 set_is_exiting();
24781 9 parser_console.kill();
24782 9 killConsole();
24783
24784 9 quit_game();
24785 9 allegro_exit();
24786 9 exit(code);
24787 }
24788
24789 42 void init_bitmap(BITMAP** bmp, int32_t w, int32_t h)
24790 {
24791
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 42 times.
42 if(*bmp)
24792 destroy_bitmap(*bmp);
24793 42 *bmp = create_bitmap_ex(8,w,h);
24794 42 clear_bitmap(*bmp);
24795 42 }
24796 6 void load_size_poses()
24797 {
24798 6 ttip_uninstall_all();
24799
24800 6 FONT* favcmdfont = get_custom_font(CFONT_FAVCMD);
24801 6 FONT* guifont = get_custom_font(CFONT_GUI);
24802
24803 6 d_nbmenu_proc(MSG_START, &dialogs[0], 0);
24804
24805 6 commands_list.xscale = command_buttonwidth;
24806 6 commands_list.yscale = 10+text_height(favcmdfont);
24807
24808 6 auto drawmode_wid = 64;
24809
2/2
✓ Branch 0 taken 36 times.
✓ Branch 1 taken 6 times.
42 for(auto q = 0; q < dm_max; ++q)
24810 {
24811 36 auto wid = text_length(guifont, dm_names[q]);
24812
1/2
✓ Branch 0 taken 36 times.
✗ Branch 1 not taken.
36 if(wid > drawmode_wid)
24813 drawmode_wid = wid;
24814 36 }
24815
24816 //Main GUI objects
24817
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(is_compact)
24818 {
24819 6 num_combo_cols = 2;
24820 6 combo_col_scale = 16;
24821
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(compact_merged_combopane)
24822 {
24823 6 num_combo_cols = 1;
24824 6 combo_col_scale = 32;
24825 6 }
24826
24827 6 mapscreen_x=0;
24828 6 mapscreen_y=dialogs[0].h;
24829 6 mapscreen_screenunit_scale=3;
24830 6 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
24831 6 showedges=0;
24832 6 showallpanels=0;
24833
24834 6 blackout_color=8;
24835
24836 6 auto mapscr_wid = (((showedges?2:0)+16)*16*mapscreen_screenunit_scale);
24837 6 combolist_window.w=zq_screen_w-mapscr_wid;
24838 6 combolist_window.x=zq_screen_w-combolist_window.w;
24839
24840 6 favorites_window.x=combolist_window.x;
24841 6 favorites_window.w=combolist_window.w;
24842 6 favorites_window.h=136;
24843 6 favorites_window.y=zq_screen_h-favorites_window.h;
24844
24845 6 combolist_window.y=0;
24846 6 combolist_window.h=favorites_window.y-combolist_window.y;
24847
24848 6 combo_preview.x=zq_screen_w-32-8;
24849 6 combo_preview.y=combolist_window.y+6;
24850 6 combo_preview.w=32;
24851 6 combo_preview.h=32;
24852 6 combo_preview2.clear();
24853
24854 6 auto col_wid = 4*combo_col_scale;
24855 6 auto cols_wid = col_wid * num_combo_cols;
24856 6 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
24857
2/2
✓ Branch 0 taken 6 times.
✓ Branch 1 taken 6 times.
12 for(auto q = 0; q < num_combo_cols; ++q)
24858 {
24859 6 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
24860 6 combolist[q].y=combolist_window.y+54;
24861 6 combolist[q].w=4;
24862 6 combolist[q].h=compact_merged_combopane ? 15 : 30;
24863 6 combolist[q].xscale = combo_col_scale;
24864 6 combolist[q].yscale = combo_col_scale;
24865
24866 6 comboaliaslist[q].x = combolist[q].x;
24867 6 comboaliaslist[q].y = combolist[q].y;
24868 6 comboaliaslist[q].w = 4;
24869 6 comboaliaslist[q].h = compact_merged_combopane ? 13 : 26;
24870 6 comboaliaslist[q].xscale = combo_col_scale;
24871 6 comboaliaslist[q].yscale = combo_col_scale;
24872
24873 6 combolistscrollers[q].w=2;
24874 6 combolistscrollers[q].h=1;
24875 6 combolistscrollers[q].xscale=11;
24876 6 combolistscrollers[q].yscale=11;
24877 6 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
24878 6 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-3;
24879 6 }
24880
24881 6 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
24882 6 comboalias_preview.h=64;
24883 6 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
24884 6 comboalias_preview.w=64;
24885
24886 6 combo_merge_btn.w = 20;
24887 6 combo_merge_btn.h = 20;
24888 6 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
24889 6 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
24890
24891
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(num_combo_cols == 1)
24892 {
24893 6 combolistscrollers[0].x += 34;
24894 6 }
24895 6 drawmode_btn.x = combolist_window.x-drawmode_wid;
24896 6 drawmode_btn.y = 0;
24897 6 drawmode_btn.w = drawmode_wid;
24898 6 drawmode_btn.h = mapscreen_y;
24899
24900 6 compactbtn.w = text_length(guifont,"> Compact")+10;
24901 6 compactbtn.x = drawmode_btn.x-compactbtn.w;
24902 6 compactbtn.y = drawmode_btn.y;
24903 6 compactbtn.h = drawmode_btn.h;
24904
24905 6 zoominbtn.w = text_length(guifont,"+")+10;
24906 6 zoominbtn.x = compactbtn.x-zoominbtn.w;
24907 6 zoominbtn.y = compactbtn.y;
24908 6 zoominbtn.h = compactbtn.h;
24909
24910 6 zoomoutbtn.w = text_length(guifont,"-")+10;
24911 6 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
24912 6 zoomoutbtn.y = compactbtn.y;
24913 6 zoomoutbtn.h = compactbtn.h;
24914
24915
2/2
✓ Branch 0 taken 54 times.
✓ Branch 1 taken 6 times.
60 for(int32_t i=0; i<=8; i++)
24916 {
24917 54 map_page_bar[i].w = 48;
24918 54 map_page_bar[i].x = mapscreen_x+(i*48);
24919 54 map_page_bar[i].y = mapscreen_y+(11*16*mapscreen_screenunit_scale);
24920 54 map_page_bar[i].h = text_height(guifont)+12;
24921 54 }
24922
24923 6 minimap.w=7+48*3;
24924 6 minimap.h=16+27*3;
24925
24926 6 layer_panel.x=map_page_bar[6].x;
24927 6 layer_panel.y=map_page_bar[0].y;
24928 6 layer_panel.w=combolist_window.x - layer_panel.x;
24929 6 layer_panel.h=map_page_bar[0].h;
24930 6 layerpanel_buttonwidth = 51;
24931 6 layerpanel_buttonheight = layer_panel.h;
24932 6 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
24933 6 layerpanel_checkbox_wid = 15;
24934
24935 6 minimap.x=3;
24936 6 minimap.y=layer_panel.y+layer_panel.h+4;
24937
24938 6 real_minimap.x = minimap.x+3;
24939 6 real_minimap.y = minimap.y+5;
24940 6 real_minimap.w = 16;
24941 6 real_minimap.h = 9;
24942 6 real_minimap.xscale = 9;
24943 6 real_minimap.yscale = 9;
24944 6 real_minimap.fw = real_minimap.xscale*8;
24945 6 real_minimap.fh = real_minimap.yscale*8;
24946
24947 6 int upscale_mm = 3;
24948 6 int xwid = real_minimap.tw()*(upscale_mm-1);
24949 6 int xhei = real_minimap.th()*(upscale_mm-1);
24950 6 minimap_zoomed.set(minimap.x, minimap.y-xhei, minimap.w+xwid, minimap.h+xhei+4);
24951 6 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
24952 6 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
24953 6 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
24954
24955 6 screrrorpos.x = combolist_window.x - 3;
24956 6 screrrorpos.y = layer_panel.y - 16;
24957
24958 6 mouse_scroll_h=10;
24959
24960 6 favorites_list.x=favorites_window.x+8;
24961 6 favorites_list.y=favorites_window.y+16;
24962 6 favorites_list.xscale = 16;
24963 6 favorites_list.yscale = 16;
24964 6 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
24965 6 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
24966
24967 6 commands_list.w=4;
24968
24969 6 int bh = commands_list.yscale;
24970 6 int bw = 26;
24971 6 commands_window.w=commands_list.w*commands_list.xscale+10+bw;
24972 6 commands_window.x=combolist_window.x-commands_window.w;
24973 6 commands_window.y=layer_panel.y+layer_panel.h;
24974 6 commands_window.h=zq_screen_h-commands_window.y;
24975 6 int bx = commands_window.x+2;
24976
24977 6 commands_list.y=commands_window.y+4;
24978 6 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
24979 6 commands_list.x=bx+bw;
24980
24981 6 commands_zoombtn.w = bw;
24982 6 commands_zoombtn.h = bh;
24983 6 commands_zoombtn.x = bx;
24984 6 commands_zoombtn.y = commands_list.y;
24985
24986 6 commands_infobtn.w = bw;
24987 6 commands_infobtn.h = bh;
24988 6 commands_infobtn.x = bx;
24989 6 commands_infobtn.y = commands_zoombtn.y + commands_infobtn.h;
24990
24991 6 commands_x.w = bw;
24992 6 commands_x.h = bh;
24993 6 commands_x.x = bx;
24994 6 commands_x.y = commands_infobtn.y + commands_x.h;
24995
24996 6 commands_txt.clear();
24997
24998 6 main_panel.x = 0;
24999 6 main_panel.y = layer_panel.y+layer_panel.h;
25000 6 main_panel.w = commands_window.x - main_panel.x;
25001 6 main_panel.h = 76+32;
25002 6 preview_panel = main_panel;
25003 6 preview_panel.x = 0;
25004 6 preview_panel.w = commands_window.x - preview_panel.x;
25005
25006 6 preview_text.x = preview_panel.x+3;
25007 6 preview_text.y = preview_panel.y+3;
25008 6 preview_text.w = 2;
25009 6 preview_text.h = 6;
25010 6 preview_text.xscale = 10;
25011 6 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
25012
25013 6 panel_align = 1;
25014 6 int swapbtnw = 32, swapbtnh = 20;
25015 6 int swapbtnx = main_panel.x+main_panel.tw()-swapbtnw;
25016 6 squarepanel_swap_btn.set(swapbtnx, zq_screen_h-swapbtnh, swapbtnw, swapbtnh);
25017
25018 6 int sqx = minimap.x+minimap.tw();
25019 6 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
25020
1/2
✗ Branch 0 not taken.
✓ Branch 1 taken 6 times.
6 if(compact_square_panels)
25021 {
25022 int cmpy = main_panel.y+(main_panel.th()/2);
25023 squarepanel_up_btn.set(swapbtnx, cmpy-swapbtnh, swapbtnw, swapbtnh);
25024 squarepanel_down_btn.set(swapbtnx, cmpy, swapbtnw, swapbtnh);
25025
25026 txtoffs_single.x = 18;
25027 txtoffs_single.y = 36;
25028 txtoffs_double_1.x = 18;
25029 txtoffs_double_1.y = 36;
25030 txtoffs_double_2.x = 18;
25031 txtoffs_double_2.y = 36 + text_height(get_custom_font(CFONT_GUI));
25032
25033 //Clear them all- if they stay cleared, they are invisible.
25034 itemsqr_pos.clear();
25035 stairsqr_pos.clear();
25036 warparrival_pos.clear();
25037 flagsqr_pos.clear();
25038 enemy_prev_pos.clear();
25039 for(int q = 0; q < 4; ++q)
25040 warpret_pos[q].clear();
25041
25042 int sqr_x1 = sqx+12;
25043 int sqr_y1 = main_panel.y+12;
25044 int sqr_xoffs = (16*2)+4 + 12;
25045 switch(compact_active_panel)
25046 {
25047 case 0: //Warp Squares
25048 {
25049 int x = sqr_x1;
25050 for(int q = 0; q < 4; ++q)
25051 {
25052 warpret_pos[q].set(x,sqr_y1,(16*2)+4,(16*2)+4);
25053 x += sqr_xoffs;
25054 }
25055 break;
25056 }
25057 case 1: //Other Squares
25058 {
25059 itemsqr_pos.set(sqr_x1+(sqr_xoffs*0), sqr_y1, (16*2)+4,(16*2)+4);
25060 stairsqr_pos.set(sqr_x1+(sqr_xoffs*1), sqr_y1, (16*2)+4,(16*2)+4);
25061 warparrival_pos.set(sqr_x1+(sqr_xoffs*2), sqr_y1, (16*2)+4,(16*2)+4);
25062 flagsqr_pos.set(sqr_x1+(sqr_xoffs*3), sqr_y1, (16*2)+4,(16*2)+4);
25063 break;
25064 }
25065 case 2: //Enemy Preview
25066 {
25067 enemy_prev_pos.set(sqr_x1, sqr_y1, 5, 2, 32, 32);
25068 break;
25069 }
25070 }
25071 }
25072 else
25073 {
25074 6 squarepanel_up_btn.clear();
25075 6 squarepanel_down_btn.clear();
25076 6 txtoffs_single.x = 10;
25077 6 txtoffs_single.y = 22;
25078 6 txtoffs_double_1.x = 10;
25079 6 txtoffs_double_1.y = 22;
25080 6 txtoffs_double_2.x = 10;
25081 6 txtoffs_double_2.y = 30;
25082
25083
25084 6 int sqr_x1 = sqx+24;
25085 6 int sqr_y1 = main_panel.y+12;
25086 6 int sqr_y2 = sqr_y1+42;
25087 6 int sqr_xdist = 32;
25088 6 itemsqr_pos.set(sqr_x1+(sqr_xdist*0),sqr_y1,20,20);
25089 6 stairsqr_pos.set(sqr_x1+(sqr_xdist*1),sqr_y1,20,20);
25090 6 warparrival_pos.set(sqr_x1+(sqr_xdist*2),sqr_y1,20,20);
25091 6 flagsqr_pos.set(sqr_x1+(sqr_xdist*3),sqr_y1,20,20);
25092
2/2
✓ Branch 0 taken 24 times.
✓ Branch 1 taken 6 times.
30 for(auto q = 0; q < 4; ++q)
25093 {
25094 24 warpret_pos[q].set(sqr_x1+(sqr_xdist*q),sqr_y2,20,20);
25095 24 }
25096 6 enemy_prev_pos.set(sqr_x1+(sqr_xdist*4), sqr_y1, 4, 3, 16, 16);
25097 6 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
25098 6 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
25099 }
25100
25101 6 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
25102 6 combopool_preview.x=comboaliaslist[0].x;
25103 6 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
25104 6 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
25105 6 combopool_preview.h=zq_screen_h-8-combopool_preview.y;
25106 6 combopool_preview.w -= combopool_preview.w%16;
25107 6 combopool_preview.h -= combopool_preview.h%16;
25108
25109 6 FONT* tfont = get_zc_font(font_lfont_l);
25110 6 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
25111 6 combopool_prevbtn.h = 11;
25112 6 combopool_prevbtn.x = combopool_preview.x;
25113 6 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
25114
25115 6 mappage_count = 6;
25116
25117 6 txfont = get_zc_font(font_lfont_l);
25118 6 combo_preview_text1.set(combo_preview.x-5,combo_preview.y,1,3,1,text_height(txfont));
25119 6 combo_preview_text2.clear();
25120
25121 6 favorites_x.w = 17;
25122 6 favorites_infobtn.w = 17;
25123 6 favorites_zoombtn.w = 17;
25124 6 favorites_pgleft.w = 17;
25125 6 favorites_pgright.w = 17;
25126 6 }
25127 else
25128 {
25129 num_combo_cols = 4;
25130 combo_col_scale = 16;
25131 if(large_merged_combopane)
25132 {
25133 num_combo_cols = 2;
25134 combo_col_scale = 32;
25135 }
25136
25137 mapscreen_x=0;
25138 mapscreen_y=dialogs[0].h;
25139 mapscreen_screenunit_scale=2;
25140 mapscreen_single_scale = (double)mapscreen_screenunit_scale / Map.getViewSize();
25141 showedges=Map.getViewSize() <= 2 ? 1 : 0;
25142 showallpanels=0;
25143
25144 blackout_color=8;
25145
25146 favorites_window.h=136;
25147 favorites_window.y=zq_screen_h-favorites_window.h;
25148
25149 auto mapscr_wid = (((2)+16)*16*mapscreen_screenunit_scale);
25150 combolist_window.w=zq_screen_w-mapscr_wid;
25151 combolist_window.x=zq_screen_w-combolist_window.w;
25152 combolist_window.y=0;
25153 combolist_window.h=favorites_window.y-combolist_window.y;
25154
25155 favorites_window.x=combolist_window.x;
25156 favorites_window.w=combolist_window.w;
25157
25158 combo_preview.x=(zq_screen_w-(combolist_window.w/2))-40;
25159 combo_preview.y=combolist_window.y+6;
25160 combo_preview.w=32;
25161 combo_preview.h=32;
25162 combo_preview2 = combo_preview;
25163 combo_preview2.x += 48;
25164
25165 auto col_wid = 4*combo_col_scale;
25166 auto cols_wid = col_wid * num_combo_cols;
25167 auto cols_spacing = (combolist_window.w-cols_wid)/(num_combo_cols+1);
25168 for(auto q = 0; q < num_combo_cols; ++q)
25169 {
25170 combolist[q].x=combolist_window.x+(cols_spacing*(q+1))+(col_wid*q);
25171 combolist[q].y=combolist_window.y+60;
25172 combolist[q].w=4;
25173 combolist[q].h=large_merged_combopane ? 15 : 30;
25174 combolist[q].xscale = combo_col_scale;
25175 combolist[q].yscale = combo_col_scale;
25176
25177 comboaliaslist[q].x=combolist[q].x;
25178 comboaliaslist[q].y=combolist[q].y;
25179 comboaliaslist[q].w=4;
25180 comboaliaslist[q].h=large_merged_combopane ? 12 : 25;
25181 comboaliaslist[q].xscale = combo_col_scale;
25182 comboaliaslist[q].yscale = combo_col_scale;
25183
25184 combolistscrollers[q].w=2;
25185 combolistscrollers[q].h=1;
25186 combolistscrollers[q].xscale=11;
25187 combolistscrollers[q].yscale=11;
25188 combolistscrollers[q].x=combolist[q].x+(combolist[q].w*combolist[q].xscale/2)-11;
25189 combolistscrollers[q].y=combolist[q].y-combolistscrollers[q].th()-2;
25190 }
25191
25192 comboalias_preview.x=zq_screen_w-((combolist_window.w+64)/2);
25193 comboalias_preview.h=64;
25194 comboalias_preview.w=64;
25195 comboalias_preview.y=favorites_window.y-comboalias_preview.h-8;
25196
25197 combo_merge_btn.w = 20;
25198 combo_merge_btn.h = 20;
25199 combo_merge_btn.x = zq_screen_w-(combolist_window.w+combo_merge_btn.w)/2;
25200 combo_merge_btn.y = combolist[0].y-combo_merge_btn.h;
25201 squarepanel_swap_btn.clear();
25202 squarepanel_up_btn.clear();
25203 squarepanel_down_btn.clear();
25204
25205 drawmode_btn.x = combolist_window.x-drawmode_wid;
25206 drawmode_btn.y = 0;
25207 drawmode_btn.w = drawmode_wid;
25208 drawmode_btn.h = mapscreen_y;
25209
25210 compactbtn.w = text_length(guifont,"> Compact")+10;
25211 compactbtn.x = drawmode_btn.x-compactbtn.w;
25212 compactbtn.y = drawmode_btn.y;
25213 compactbtn.h = drawmode_btn.h;
25214
25215 zoominbtn.w = text_length(guifont,"+")+10;
25216 zoominbtn.x = compactbtn.x-zoominbtn.w;
25217 zoominbtn.y = compactbtn.y;
25218 zoominbtn.h = compactbtn.h;
25219
25220 zoomoutbtn.w = text_length(guifont,"-")+10;
25221 zoomoutbtn.x = zoominbtn.x-zoomoutbtn.w;
25222 zoomoutbtn.y = compactbtn.y;
25223 zoomoutbtn.h = compactbtn.h;
25224
25225 for(int32_t i=0; i<=8; i++)
25226 {
25227 map_page_bar[i].x = mapscreen_x+(i*16*2*mapscreen_screenunit_scale);
25228 map_page_bar[i].y = mapscreen_y+((13)*16*mapscreen_screenunit_scale);
25229 map_page_bar[i].w = 64;
25230 map_page_bar[i].h = text_height(guifont)+12;
25231 }
25232
25233 minimap.w=7+48*3;
25234 minimap.h=16+27*3;
25235
25236 layer_panel.x=map_page_bar[0].x;
25237 layer_panel.y=map_page_bar[0].y+map_page_bar[0].h;
25238 layer_panel.w=map_page_bar[8].x+map_page_bar[8].w;
25239 layer_panel.h=text_height(guifont)+8;
25240 layerpanel_buttonwidth = 58;
25241 layerpanel_buttonheight = layer_panel.h;
25242 layerpanel_checkbox_hei = layerpanel_buttonheight-4;
25243 layerpanel_checkbox_wid = 14;
25244
25245 commands_list.w=4;
25246 commands_window.w=commands_list.w*commands_list.xscale+16;
25247 commands_window.x=combolist_window.x-commands_window.w;
25248 commands_window.y=layer_panel.y+layer_panel.h;
25249 commands_window.h=zq_screen_h-commands_window.y;
25250
25251 //buttons panel
25252 main_panel.x = 0;
25253 main_panel.y = layer_panel.y+layer_panel.h;
25254 main_panel.w = commands_window.x - main_panel.x;
25255 main_panel.h = zq_screen_h - main_panel.y;
25256 preview_panel = main_panel;
25257
25258 preview_text.x = preview_panel.x+3;
25259 preview_text.y = preview_panel.y+3;
25260 preview_text.w = 1;
25261 preview_text.h = 12;
25262 preview_text.xscale = 10;
25263 preview_text.yscale = text_height(get_zc_font(font_lfont_l));
25264
25265 minimap.x=3;
25266 minimap.y=main_panel.y+4;
25267
25268 real_minimap.x = minimap.x+3;
25269 real_minimap.y = minimap.y+5;
25270 real_minimap.w = 16;
25271 real_minimap.h = 9;
25272 real_minimap.xscale = 9;
25273 real_minimap.yscale = 9;
25274 real_minimap.fw = real_minimap.xscale*8;
25275 real_minimap.fh = real_minimap.yscale*8;
25276
25277 int upscale_mm = 4;
25278 int xwid = real_minimap.tw()*(upscale_mm-1);
25279 int xhei = real_minimap.th()*(upscale_mm-1);
25280 int zh = minimap.h+xhei+4;
25281 minimap_zoomed.set(minimap.x, zq_screen_h-zh, minimap.w+xwid, zh);
25282 real_minimap_zoomed.set(minimap_zoomed.x+3, minimap_zoomed.y+5, real_minimap.w, real_minimap.h, real_minimap.xscale*upscale_mm, real_minimap.yscale*upscale_mm);
25283 real_minimap_zoomed.fw = real_minimap_zoomed.xscale*8;
25284 real_minimap_zoomed.fh = real_minimap_zoomed.yscale*8;
25285
25286 screrrorpos.x = 575;
25287 screrrorpos.y = 388;
25288
25289 mouse_scroll_h=10;
25290
25291 favorites_list.x=favorites_window.x+8;
25292 favorites_list.y=favorites_window.y+16;
25293 favorites_list.xscale = 16;
25294 favorites_list.yscale = 16;
25295 favorites_list.w=(favorites_window.w-16)/favorites_list.xscale;
25296 favorites_list.h=(favorites_window.h-24)/favorites_list.yscale;
25297
25298 int bh = 16;
25299 int by = commands_window.y+4;
25300 commands_list.y=by+bh;
25301 commands_list.h=(zq_screen_h - commands_list.y) / commands_list.yscale;
25302 commands_list.x=commands_window.x+8;
25303
25304 commands_x.w = 20;
25305 commands_x.h = bh;
25306 commands_x.x = commands_list.x + commands_list.tw() - commands_x.w;
25307 commands_x.y = by;
25308
25309 commands_infobtn.w = 20;
25310 commands_infobtn.h = bh;
25311 commands_infobtn.x = commands_x.x - commands_infobtn.w;
25312 commands_infobtn.y = by;
25313
25314 commands_zoombtn.w = 20;
25315 commands_zoombtn.h = bh;
25316 commands_zoombtn.x = commands_infobtn.x - commands_zoombtn.w;
25317 commands_zoombtn.y = by;
25318
25319 commands_txt.x = commands_list.x;
25320 commands_txt.y = by+(bh-text_height(get_zc_font(font_lfont_l)))/2;
25321
25322 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
25323 favorites_x.y = favorites_list.y-15;
25324
25325 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
25326 favorites_infobtn.y = favorites_x.y;
25327
25328 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
25329 favorites_zoombtn.y = favorites_infobtn.y;
25330
25331 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
25332 favorites_pgright.y = favorites_zoombtn.y;
25333
25334 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
25335 favorites_pgleft.y = favorites_pgleft.y;
25336
25337 txtoffs_single.x = 22;
25338 txtoffs_single.y = 6;
25339 txtoffs_double_1.x = 22;
25340 txtoffs_double_1.y = 2;
25341 txtoffs_double_2.x = 22;
25342 txtoffs_double_2.y = 10;
25343 panel_align = 0;
25344
25345 int sqx = minimap.x+minimap.tw();
25346 squares_panel.set(sqx,main_panel.y,main_panel.tw()-sqx,main_panel.th());
25347 int x2 = sqx+4;
25348 int x1 = x2 - (20+(8*3)+2);
25349 int y1 = main_panel.y+10;
25350 int sw = 20, sh = 20;
25351 int offs = sh+4;
25352
25353 itemsqr_pos.set(x2,y1+(0*offs),sw,sh);
25354 flagsqr_pos.set(x2,y1+(1*offs),sw,sh);
25355 stairsqr_pos.set(x2,y1+(2*offs),sw,sh);
25356 warparrival_pos.set(x2,y1+(6*offs),sw,sh);
25357
25358 enemy_prev_pos.x = main_panel.x+14;
25359 enemy_prev_pos.y = main_panel.y+12 + minimap.h;
25360 enemy_prev_pos.w = 4;
25361 enemy_prev_pos.h = 3;
25362 enemy_prev_pos.xscale = 16;
25363 enemy_prev_pos.yscale = 16;
25364 enemy_prev_pos.fw = enemy_prev_pos.xscale*2;
25365 enemy_prev_pos.fh = enemy_prev_pos.yscale*2;
25366
25367 warpret_pos[0].set(x1,y1+(4*offs),sw,sh);
25368 warpret_pos[1].set(x1,y1+(5*offs),sw,sh);
25369 warpret_pos[2].set(x2,y1+(4*offs),sw,sh);
25370 warpret_pos[3].set(x2,y1+(5*offs),sw,sh);
25371
25372 auto& last_alias_list = comboaliaslist[num_combo_cols-1];
25373 combopool_preview.x=comboaliaslist[0].x;
25374 combopool_preview.y=last_alias_list.y+(last_alias_list.h*last_alias_list.yscale)+16;
25375 combopool_preview.w=(last_alias_list.x+(last_alias_list.w*last_alias_list.xscale))-comboaliaslist[0].x;
25376 combopool_preview.h=(favorites_window.y-combopool_preview.y);//+favorites_window.h-10;
25377 combopool_preview.w -= combopool_preview.w%16;
25378 combopool_preview.h -= combopool_preview.h%16;
25379
25380 FONT* tfont = get_zc_font(font_lfont_l);
25381 combopool_prevbtn.w = text_length(tfont, "Unweighted")+10;
25382 combopool_prevbtn.h = 11;
25383 combopool_prevbtn.x = combopool_preview.x;
25384 combopool_prevbtn.y = combopool_preview.y-combopool_prevbtn.h;
25385
25386 mappage_count = 9;
25387
25388 txfont = get_zc_font(font_lfont_l);
25389 combo_preview_text1.set(combo_preview.x-9,combo_preview.y,1,3,1,text_height(txfont));
25390 combo_preview_text2.set(combo_preview2.x+combo_preview2.w+8,combo_preview2.y,1,3,1,text_height(txfont));
25391
25392 favorites_x.w = 30;
25393 favorites_infobtn.w = 30;
25394 favorites_zoombtn.w = 30;
25395 favorites_pgleft.w = 30;
25396 favorites_pgright.w = 30;
25397 }
25398 //Same in all modes
25399 {
25400
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(is_compact ? compact_zoomed_cmd : large_zoomed_cmd)
25401 {
25402 6 commands_list.w /= 2;
25403 6 commands_list.xscale *= 2;
25404 6 }
25405
2/4
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 6 times.
6 if(is_compact ? compact_zoomed_fav : large_zoomed_fav)
25406 {
25407
1/2
✓ Branch 0 taken 6 times.
✗ Branch 1 not taken.
6 if(favorites_list.w%2)
25408 favorites_list.x += (favorites_list.xscale / 2);
25409 6 favorites_list.xscale *= 2;
25410 6 favorites_list.yscale *= 2;
25411 6 favorites_list.w /= 2;
25412 6 favorites_list.h /= 2;
25413 6 }
25414
25415 6 favorites_x.h = 14;
25416 6 favorites_x.x = favorites_window.x + favorites_window.w - favorites_x.w - 2;
25417 6 favorites_x.y = favorites_list.y-15;
25418
25419 6 favorites_infobtn.h = favorites_x.h;
25420 6 favorites_infobtn.x = favorites_x.x - favorites_infobtn.w;
25421 6 favorites_infobtn.y = favorites_x.y;
25422
25423 6 favorites_zoombtn.h = favorites_infobtn.h;
25424 6 favorites_zoombtn.x = favorites_infobtn.x - favorites_zoombtn.w;
25425 6 favorites_zoombtn.y = favorites_infobtn.y;
25426
25427 6 favorites_pgright.h = favorites_zoombtn.h;
25428 6 favorites_pgright.x = favorites_zoombtn.x - favorites_pgright.w;
25429 6 favorites_pgright.y = favorites_zoombtn.y;
25430
25431 6 favorites_pgleft.h = favorites_pgright.h;
25432 6 favorites_pgleft.x = favorites_pgright.x - favorites_pgleft.w;
25433 6 favorites_pgleft.y = favorites_pgright.y;
25434
25435 6 mainbar.x = dialogs[0].x+dialogs[0].w;
25436 6 mainbar.y = 0;
25437 6 mainbar.w = zoomoutbtn.x-mainbar.x;
25438 6 mainbar.h = drawmode_btn.h;
25439 }
25440
25441 //Ensure current combo list selected is valid
25442 6 current_combolist=vbound(current_combolist,0,num_combo_cols-1);
25443 6 current_comboalist=vbound(current_comboalist,0,num_combo_cols-1);
25444 6 current_cpoollist=vbound(current_cpoollist,0,num_combo_cols-1);
25445 6 current_cautolist = vbound(current_cautolist, 0, num_combo_cols - 1);
25446
25447 //Generate bitmaps
25448 6 init_bitmap(&mapscreenbmp,16*(showedges?18:16),16*(showedges?13:11));
25449 6 init_bitmap(&brushbmp,256*mapscreen_screenunit_scale,176*mapscreen_screenunit_scale);
25450 6 init_bitmap(&brushscreen,(256+(showedges?16:0))*mapscreen_screenunit_scale,(176+(showedges?16:0))*mapscreen_screenunit_scale);
25451
25452 6 init_bitmap(&screen2,zq_screen_w,zq_screen_h);
25453 6 init_bitmap(&tmp_scr,zq_screen_w,zq_screen_h);
25454 6 init_bitmap(&menu1,zq_screen_w,zq_screen_h);
25455 6 init_bitmap(&menu3,zq_screen_w,zq_screen_h);
25456
25457 6 center_zq_class_dialogs();
25458 6 center_zq_custom_dialogs();
25459 6 center_zq_files_dialogs();
25460 6 center_zq_subscreen_dialogs();
25461 6 center_zq_tiles_dialogs();
25462 6 center_zquest_dialogs();
25463
25464 6 aspect_ratio = zq_screen_h / double(zq_screen_w);
25465
25466 6 mmap_init();
25467 6 }
25468
25469 9 void remove_locked_params_on_exit()
25470 {
25471 9 al_trace("Removing timers. \n");
25472 9 remove_int(fps_callback);
25473 9 remove_int(dclick_check);
25474 9 }
25475
25476 9 void destroy_bitmaps_on_exit()
25477 {
25478 9 al_trace("Cleaning bitmaps...");
25479 9 destroy_bitmap(screen2);
25480 9 destroy_bitmap(tmp_scr);
25481 9 destroy_bitmap(menu1);
25482 9 destroy_bitmap(menu3);
25483 9 destroy_bitmap(mapscreenbmp);
25484 9 destroy_bitmap(dmapbmp_small);
25485 9 destroy_bitmap(dmapbmp_large);
25486 9 destroy_bitmap(brushbmp);
25487 9 destroy_bitmap(brushscreen);
25488 9 al_trace("...");
25489
25490
2/2
✓ Branch 0 taken 432 times.
✓ Branch 1 taken 9 times.
441 for(int32_t i=0; i<MOUSE_BMP_MAX*4; i++)
25491 {
25492 432 destroy_bitmap(mouse_bmp[i/4][i%4]);
25493 432 destroy_bitmap(mouse_bmp_1x[i/4][i%4]);
25494 432 }
25495
25496
2/2
✓ Branch 0 taken 288 times.
✓ Branch 1 taken 9 times.
297 for(int32_t i=0; i<ICON_BMP_MAX*4; i++)
25497 288 destroy_bitmap(icon_bmp[i/4][i%4]);
25498
25499
2/2
✓ Branch 0 taken 576 times.
✓ Branch 1 taken 9 times.
585 for(int32_t i=0; i<16*4; i++)
25500 576 destroy_bitmap(flag_bmp[i/4][i%4]);
25501
2/2
✓ Branch 0 taken 18 times.
✓ Branch 1 taken 9 times.
27 for(int32_t i=0; i<2; i++)
25502 18 destroy_bitmap(select_bmp[i]);
25503
25504
2/2
✓ Branch 0 taken 72 times.
✓ Branch 1 taken 9 times.
81 for(int32_t i=0; i<MAXARROWS; i++)
25505 72 destroy_bitmap(arrow_bmp[i]);
25506
25507 9 al_trace(" OK. \n");
25508 9 }
25509
25510
25511 9 void quit_game()
25512 {
25513 9 set_last_timed_save(nullptr);
25514 9 save_config_file();
25515 9 zc_set_palette(black_palette);
25516 9 zc_stop_midi();
25517
25518 9 remove_locked_params_on_exit();
25519
25520 9 al_trace("Cleaning sfx. \n");
25521
25522
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<WAV_COUNT; i++)
25523 {
25524
2/2
✓ Branch 0 taken 2295 times.
✓ Branch 1 taken 9 times.
2304 if(customsfxdata[i].data!=NULL)
25525 {
25526 // delete [] customsfxdata[i].data;
25527 2295 free(customsfxdata[i].data);
25528 2295 }
25529
25530
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete [] sfx_string[i];
25531 2304 }
25532
25533
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<MAXWPNS; i++)
25534 {
25535
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete [] weapon_string[i];
25536 2304 }
25537
25538
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<MAXITEMS; i++)
25539 {
25540
1/2
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
2304 delete [] item_string[i];
25541 2304 }
25542
25543
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<eMAXGUYS; i++)
25544 {
25545
1/2
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
4608 delete [] guy_string[i];
25546 4608 }
25547
25548 9 al_trace("Cleaning script buffer. \n");
25549
25550
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
25551 {
25552
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(ffscripts[i]!=NULL) delete ffscripts[i];
25553 4608 }
25554
25555
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
25556 {
25557
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(itemscripts[i]!=NULL) delete itemscripts[i];
25558 2304 }
25559
25560
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
25561 {
25562
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(guyscripts[i]!=NULL) delete guyscripts[i];
25563 2304 }
25564
25565
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25566 {
25567
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
25568 2304 }
25569
25570
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25571 {
25572
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
25573 2304 }
25574
25575
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
25576 {
25577
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(screenscripts[i]!=NULL) delete screenscripts[i];
25578 2304 }
25579
25580
2/2
✓ Branch 0 taken 27 times.
✓ Branch 1 taken 9 times.
36 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
25581 {
25582
2/4
✓ Branch 0 taken 27 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 27 times.
27 if(globalscripts[i]!=NULL) delete globalscripts[i];
25583 27 }
25584
25585
2/2
✓ Branch 0 taken 45 times.
✓ Branch 1 taken 9 times.
54 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
25586 {
25587
2/4
✓ Branch 0 taken 45 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 45 times.
45 if(playerscripts[i]!=NULL) delete playerscripts[i];
25588 45 }
25589
25590
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
25591 {
25592
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25593 2304 }
25594
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25595 {
25596
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25597 2304 }
25598
2/2
✓ Branch 0 taken 4608 times.
✓ Branch 1 taken 9 times.
4617 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25599 {
25600
2/4
✓ Branch 0 taken 4608 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 4608 times.
4608 if(comboscripts[i]!=NULL) delete comboscripts[i];
25601 4608 }
25602
2/2
✓ Branch 0 taken 9 times.
✓ Branch 1 taken 2304 times.
2313 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25603 {
25604
2/4
✓ Branch 0 taken 2304 times.
✗ Branch 1 not taken.
✗ Branch 2 not taken.
✓ Branch 3 taken 2304 times.
2304 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25605 2304 }
25606
25607 9 al_trace("Cleaning qst buffers. \n");
25608 9 del_qst_buffers();
25609
25610
25611 9 al_trace("Cleaning midis. \n");
25612
25613
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(customtunes)
25614 {
25615
2/2
✓ Branch 0 taken 2304 times.
✓ Branch 1 taken 9 times.
2313 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25616 2304 customtunes[i].reset();
25617
25618 9 free(customtunes);
25619 9 }
25620
25621 9 al_trace("Cleaning undotilebuf. \n");
25622
25623 9 undocombobuf.clear();
25624
25625
2/2
✓ Branch 0 taken 7 times.
✓ Branch 1 taken 2 times.
9 if(newundotilebuf)
25626 {
25627
2/2
✓ Branch 0 taken 1501500 times.
✓ Branch 1 taken 7 times.
1501507 for(int32_t i=0; i<NEWMAXTILES; i++)
25628
1/2
✓ Branch 0 taken 1501500 times.
✗ Branch 1 not taken.
1501500 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25629
25630 7 free(newundotilebuf);
25631 7 }
25632
25633
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(filepath) free(filepath);
25634
25635
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(datapath) free(datapath);
25636
25637
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(midipath) free(midipath);
25638
25639
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(imagepath) free(imagepath);
25640
25641
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(tmusicpath) free(tmusicpath);
25642
25643
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if(last_timed_save) free(last_timed_save);
25644
25645 9 destroy_bitmaps_on_exit();
25646 9 }
25647
25648 void quit_game2()
25649 {
25650 set_last_timed_save(nullptr);
25651 save_config_file();
25652 zc_set_palette(black_palette);
25653 zc_stop_midi();
25654
25655 remove_locked_params_on_exit();
25656
25657 al_trace("Cleaning sfx. \n");
25658
25659 for(int32_t i=0; i<WAV_COUNT; i++)
25660 {
25661 if(customsfxdata[i].data!=NULL)
25662 {
25663 // delete [] customsfxdata[i].data;
25664 free(customsfxdata[i].data);
25665 }
25666
25667 delete [] sfx_string[i];
25668 }
25669
25670 for(int32_t i=0; i<MAXWPNS; i++)
25671 {
25672 delete [] weapon_string[i];
25673 }
25674
25675 for(int32_t i=0; i<MAXITEMS; i++)
25676 {
25677 delete [] item_string[i];
25678 }
25679
25680 for(int32_t i=0; i<eMAXGUYS; i++)
25681 {
25682 delete [] guy_string[i];
25683 }
25684
25685 al_trace("Cleaning script buffer. \n");
25686
25687 for(int32_t i=0; i<NUMSCRIPTFFC; i++)
25688 {
25689 if(ffscripts[i]!=NULL) delete ffscripts[i];
25690 }
25691
25692 for(int32_t i=0; i<NUMSCRIPTITEM; i++)
25693 {
25694 if(itemscripts[i]!=NULL) delete itemscripts[i];
25695 }
25696
25697 for(int32_t i=0; i<NUMSCRIPTGUYS; i++)
25698 {
25699 if(guyscripts[i]!=NULL) delete guyscripts[i];
25700 }
25701
25702 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25703 {
25704 if(lwpnscripts[i]!=NULL) delete lwpnscripts[i];
25705 }
25706
25707 for(int32_t i=0; i<NUMSCRIPTWEAPONS; i++)
25708 {
25709 if(ewpnscripts[i]!=NULL) delete ewpnscripts[i];
25710 }
25711
25712 for(int32_t i=0; i<NUMSCRIPTSCREEN; i++)
25713 {
25714 if(screenscripts[i]!=NULL) delete screenscripts[i];
25715 }
25716
25717 for(int32_t i=0; i<3; i++) //should this be NUMSCRIPTGLOBAL or NUMSCRIPTGLOBALOLD? -Z
25718 {
25719 if(globalscripts[i]!=NULL) delete globalscripts[i];
25720 }
25721
25722 for(int32_t i=0; i<NUMSCRIPTHERO; i++)
25723 {
25724 if(playerscripts[i]!=NULL) delete playerscripts[i];
25725 }
25726
25727 for(int32_t i=0; i<NUMSCRIPTSDMAP; i++)
25728 {
25729 if(dmapscripts[i]!=NULL) delete dmapscripts[i];
25730 }
25731 for(int32_t i=0; i<NUMSCRIPTSITEMSPRITE; i++)
25732 {
25733 if(itemspritescripts[i]!=NULL) delete itemspritescripts[i];
25734 }
25735 for(int32_t i=0; i<NUMSCRIPTSCOMBODATA; i++)
25736 {
25737 if(comboscripts[i]!=NULL) delete comboscripts[i];
25738 }
25739 for(int32_t i=0; i<NUMSCRIPTSSUBSCREEN; i++)
25740 {
25741 if(subscreenscripts[i]!=NULL) delete subscreenscripts[i];
25742 }
25743
25744 al_trace("Cleaning qst buffers. \n");
25745 del_qst_buffers();
25746
25747
25748 al_trace("Cleaning midis. \n");
25749
25750 if(customtunes)
25751 {
25752 for(int32_t i=0; i<MAXCUSTOMMIDIS_ZQ; i++)
25753 customtunes[i].reset();
25754
25755 free(customtunes);
25756 }
25757
25758 al_trace("Cleaning undotilebuf. \n");
25759
25760 undocombobuf.clear();
25761
25762 if(newundotilebuf)
25763 {
25764 for(int32_t i=0; i<NEWMAXTILES; i++)
25765 if(newundotilebuf[i].data) free(newundotilebuf[i].data);
25766
25767 free(newundotilebuf);
25768 }
25769
25770 if(filepath) free(filepath);
25771
25772 if(datapath) free(datapath);
25773
25774 if(midipath) free(midipath);
25775
25776 if(imagepath) free(imagepath);
25777
25778 if(tmusicpath) free(tmusicpath);
25779
25780 if(last_timed_save) free(last_timed_save);
25781 }
25782
25783 6 void center_zquest_dialogs()
25784 {
25785 6 jwin_center_dialog(assignscript_dlg);
25786 6 jwin_center_dialog(autolayer_dlg);
25787 6 center_zq_cset_dialogs();
25788 6 jwin_center_dialog(change_track_dlg);
25789 6 jwin_center_dialog(csetfix_dlg);
25790 6 jwin_center_dialog(dmapmaps_dlg);
25791 6 center_zq_door_dialogs();
25792 6 jwin_center_dialog(editcomboa_dlg);
25793 6 jwin_center_dialog(editinfo_dlg);
25794 6 jwin_center_dialog(editmusic_dlg);
25795 6 jwin_center_dialog(editshop_dlg);
25796 6 jwin_center_dialog(ffcombo_sel_dlg);
25797 6 jwin_center_dialog(getnum_dlg);
25798 6 jwin_center_dialog(layerdata_dlg);
25799 6 jwin_center_dialog(list_dlg);
25800 6 jwin_center_dialog(loadmap_dlg);
25801 6 jwin_center_dialog(misccolors_dlg);
25802 6 jwin_center_dialog(newcomboa_dlg);
25803 6 jwin_center_dialog(orgcomboa_dlg);
25804 6 jwin_center_dialog(path_dlg);
25805 6 jwin_center_dialog(screen_pal_dlg);
25806 6 jwin_center_dialog(secret_dlg);
25807 6 jwin_center_dialog(selectdmap_dlg);
25808 6 jwin_center_dialog(selectmusic_dlg);
25809 6 jwin_center_dialog(showpal_dlg);
25810 6 jwin_center_dialog(strlist_dlg);
25811 6 jwin_center_dialog(template_dlg);
25812 6 jwin_center_dialog(tp_dlg);
25813 6 jwin_center_dialog(under_dlg);
25814 6 jwin_center_dialog(tilewarp_dlg);
25815 6 jwin_center_dialog(sidewarp_dlg);
25816 6 jwin_center_dialog(warpring_dlg);
25817 6 center_zscript_dialogs();
25818 6 }
25819
25820
25821 void animate_coords()
25822 {
25823 coord_frame=(coord_timer>>3)&3;
25824
25825 if(++coord_timer>=(1<<5))
25826 {
25827 coord_timer=0;
25828 }
25829 }
25830
25831 static const char *help_list[] =
25832 {
25833 "PREVIEW MODE",
25834 "PgUp/PgDn - Scroll through hotkey list",
25835 "Esc/Enter - Exit Preview Mode",
25836 "R - Restore screen to original state",
25837 "C - Toggle combo cycling On/Off",
25838 "S - Trigger screen secrets",
25839 "Q/W/F - These still work",
25840 "P - Pause everything",
25841 "A - Advance frame-by-frame",
25842 "1-4 - Trigger tile warp A-D",
25843 "5-8 - Trigger side warp A-D",
25844 "9 - Enable timed warps",
25845 "",
25846 "",
25847 };
25848
25849 void do_previewtext()
25850 {
25851 FONT* oldfont = font;
25852 font = get_zc_font(font_lfont_l);
25853
25854 //Put in help areas
25855 auto& sqr = preview_text;
25856 int ind = 0, len = 0;
25857 for(int q = 0; q < 12; ++q)
25858 {
25859 int l = text_length(font, help_list[q]);
25860 if(len < l) len = l;
25861 }
25862 sqr.xscale = len+2;
25863 sqr.yscale = text_height(font);
25864 for(int col = 0; col < sqr.w; ++col)
25865 {
25866 for(int row = 0; row < sqr.h; ++row)
25867 {
25868 auto& line = sqr.subsquare(col,row);
25869 textprintf_ex(menu1,font,line.x,line.y,jwin_pal[jcTEXTFG],-1,"%s",help_list[ind++]);
25870 }
25871 }
25872
25873 font = oldfont;
25874 }
25875
25876
25877 bool reload_fonts = false;
25878 void run_zq_frame()
25879 {
25880 if(reload_fonts)
25881 {
25882 init_custom_fonts();
25883 load_size_poses();
25884 reload_fonts = false;
25885 }
25886
25887 domouse();
25888 custom_vsync();
25889 refresh(rCLEAR|rALL);
25890 }
25891 6 int32_t d_nbmenu_proc(int32_t msg,DIALOG *d,int32_t c)
25892 {
25893
1/3
✗ Branch 0 not taken.
✗ Branch 1 not taken.
✓ Branch 2 taken 6 times.
6 switch(msg)
25894 {
25895 case MSG_VSYNC:
25896 run_zq_frame();
25897 break;
25898 case MSG_GOTMOUSE:
25899 case MSG_XCHAR:
25900 ComboBrushPause=1;
25901 refresh(rMAP);
25902 ComboBrushPause=0;
25903 clear_tooltip();
25904 break;
25905 }
25906
25907 6 return GuiMenu::proc(msg,d,c);
25908 }
25909
25910 bool prv_press=false;
25911
25912 void dopreview()
25913 {
25914 refresh(rMAP);
25915
25916 while(!(gui_mouse_b()))
25917 {
25918 if(keypressed())
25919 {
25920 if(!prv_press)
25921 {
25922 prv_press=true;
25923
25924 switch(readkey()>>8)
25925 {
25926 case KEY_ESC:
25927 case KEY_ENTER:
25928 case KEY_ENTER_PAD:
25929 goto finished;
25930 break;
25931
25932 case KEY_F:
25933 Flags^=cFLAGS;
25934 refresh(rMAP);
25935 break;
25936
25937 case KEY_R:
25938 onReloadPreview();
25939 break;
25940
25941 case KEY_S:
25942 onSecretsPreview();
25943 break;
25944
25945 case KEY_C:
25946 onCopy();
25947 break;
25948
25949 case KEY_A:
25950 onAKey();
25951 break;
25952
25953 case KEY_P:
25954 onP();
25955 break;
25956
25957 case KEY_L:
25958 onShowDarkness();
25959 break;
25960
25961 case KEY_1:
25962 Map.prv_dowarp(0,0);
25963 prv_warp=0;
25964 break;
25965
25966 case KEY_2:
25967 Map.prv_dowarp(0,1);
25968 prv_warp=0;
25969 break;
25970
25971 case KEY_3:
25972 Map.prv_dowarp(0,2);
25973 prv_warp=0;
25974 break;
25975
25976 case KEY_4:
25977 Map.prv_dowarp(0,3);
25978 prv_warp=0;
25979 break;
25980
25981 case KEY_5:
25982 Map.prv_dowarp(1,0);
25983 prv_warp=0;
25984 break;
25985
25986 case KEY_6:
25987 Map.prv_dowarp(1,1);
25988 prv_warp=0;
25989 break;
25990
25991 case KEY_7:
25992 Map.prv_dowarp(1,2);
25993 prv_warp=0;
25994 break;
25995
25996 case KEY_8:
25997 Map.prv_dowarp(1,3);
25998 prv_warp=0;
25999 break;
26000
26001 case KEY_9:
26002 if(prv_twon)
26003 {
26004 prv_twon=0;
26005 Map.set_prvtime(0);
26006 prv_warp=0;
26007 }
26008 else
26009 {
26010 Map.set_prvtime(Map.get_prvscr()->timedwarptics);
26011 prv_twon=1;
26012 }
26013
26014 break;
26015
26016 case KEY_W:
26017 onShowWalkability();
26018 break;
26019
26020 case KEY_Q:
26021 onShowComboInfoCSet();
26022 break;
26023 }
26024 }
26025 else
26026 {
26027 readkey();
26028 }
26029 }
26030 else
26031 {
26032 prv_press=false;
26033 }
26034
26035 if(prv_warp)
26036 {
26037 Map.prv_dowarp(1,0);
26038 prv_warp=0;
26039 }
26040
26041 if(Map.get_prvfreeze())
26042 {
26043 if(Map.get_prvadvance())
26044 {
26045 custom_vsync();
26046 Map.set_prvadvance(0);
26047 }
26048 }
26049 else
26050 {
26051 custom_vsync();
26052 Map.set_prvadvance(0);
26053 }
26054
26055 refresh(rALL);
26056 }
26057
26058 finished:
26059 //Flags=of;
26060 reset_combo_animations();
26061 reset_combo_animations2();
26062 MouseSprite::set(ZQM_NORMAL);
26063 prv_mode=0;
26064 Map.set_prvcmb(0);
26065 Map.set_prvadvance(0);
26066 Map.set_prvfreeze(0);
26067 Map.set_prvtime(0);
26068 prv_warp=0;
26069 loadlvlpal(Map.getcolor());
26070 rebuild_trans_table();
26071 refresh(rMAP+rMENU);
26072
26073 while(gui_mouse_b())
26074 {
26075 /* do nothing */
26076 rest(1);
26077 }
26078 }
26079
26080 void call_vidmode_dlg();
26081 int32_t onZQVidMode()
26082 {
26083 call_vidmode_dlg();
26084 return D_O_K;
26085 }
26086
26087 bool screenIsScrolling()
26088 {
26089 return false;
26090 }
26091
26092 void write_includepaths()
26093 {
26094 FILE* f = fopen("includepaths.txt", "w");
26095 if(f)
26096 {
26097 fwrite(FFCore.includePathString,1,strlen(FFCore.includePathString),f);
26098 fclose(f);
26099 }
26100 }
26101
26102 9 int32_t save_config_file()
26103 {
26104
1/2
✓ Branch 0 taken 9 times.
✗ Branch 1 not taken.
9 if (!application_has_loaded) return 0;
26105
26106 char qtnametitle[20];
26107 char qtpathtitle[20];
26108 char *datapath2=(char *)malloc(2048);
26109 char *midipath2=(char *)malloc(2048);
26110 char *imagepath2=(char *)malloc(2048);
26111 char *tmusicpath2=(char *)malloc(2048);
26112 strcpy(datapath2, datapath);
26113 strcpy(midipath2, midipath);
26114 strcpy(imagepath2, imagepath);
26115 strcpy(tmusicpath2, tmusicpath);
26116 chop_path(datapath2);
26117 chop_path(midipath2);
26118 chop_path(imagepath2);
26119 chop_path(tmusicpath2);
26120
26121 zc_set_config("ZCMODULE","current_module",moduledata.module_name);
26122 //
26123 write_includepaths();
26124
26125 zc_set_config("zquest",data_path_name,datapath2);
26126 zc_set_config("zquest",midi_path_name,midipath2);
26127 zc_set_config("zquest",image_path_name,imagepath2);
26128 zc_set_config("zquest",tmusic_path_name,tmusicpath2);
26129
26130 if (all_get_display() && !all_get_fullscreen_flag() && SaveDragResize)
26131 {
26132 window_width = al_get_display_width(all_get_display());
26133 window_height = al_get_display_height(all_get_display());
26134 zc_set_config("zquest","window_width",window_width);
26135 zc_set_config("zquest","window_height",window_height);
26136 }
26137 if (all_get_display() && !all_get_fullscreen_flag() && SaveWinPos)
26138 {
26139 int o_window_x, o_window_y;
26140 al_get_window_position(all_get_display(), &o_window_x, &o_window_y);
26141 zc_set_config("zquest", "window_x", o_window_x);
26142 zc_set_config("zquest", "window_y", o_window_y);
26143 }
26144
26145 byte b = 0;
26146 for(int32_t x=0; x<7; x++)
26147 {
26148 set_bit(&b,x,LayerMaskInt[x]);
26149 }
26150
26151 zc_set_config("zquest","layer_mask",b);
26152
26153 flush_config_file();
26154 #ifdef __EMSCRIPTEN__
26155 em_sync_fs();
26156 #endif
26157 free(datapath2);
26158 free(midipath2);
26159 free(imagepath2);
26160 free(tmusicpath2);
26161 return 0;
26162 9 }
26163
26164 int32_t d_timer_proc(int32_t msg, DIALOG *d, int32_t c)
26165 {
26166 //these are here to bypass compiler warnings about unused arguments
26167 c=c;
26168 d=d;
26169
26170 switch(msg)
26171 {
26172 case MSG_IDLE:
26173 #ifdef _WIN32
26174 if(zqUseWin32Proc != FALSE)
26175 win32data.Update(Frameskip); //experimental win32 fixes
26176
26177 #endif
26178
26179 // This has been crashing on Windows, and it saves plenty without it
26180 //check_autosave();
26181 break;
26182 }
26183
26184 return D_O_K;
26185 }
26186
26187 void check_autosave()
26188 {
26189 if (!first_save)
26190 return;
26191
26192 if(AutoSaveInterval>0)
26193 {
26194 time(&auto_save_time_current);
26195 auto_save_time_diff = difftime(auto_save_time_current,auto_save_time_start);
26196
26197 if(auto_save_time_diff>AutoSaveInterval*60)
26198 {
26199 MouseSprite::set(ZQM_NORMAL);
26200 replace_extension(last_timed_save, filepath, "qt0", 2047);
26201 set_last_timed_save(last_timed_save);
26202 go();
26203
26204 if((header.zelda_version != ZELDA_VERSION || header.build != VERSION_BUILD))
26205 {
26206 jwin_alert("Auto Save","This quest was saved in an older version of ZQuest.","If you wish to use the autosave feature, you must manually","save the files in this version first.","OK",NULL,13,27,get_zc_font(font_lfont));
26207 time(&auto_save_time_start);
26208 comeback();
26209 return;
26210 }
26211
26212 int32_t ret = save_quest(last_timed_save, true);
26213
26214 if(ret)
26215 {
26216 jwin_alert("Error","Timed save did not complete successfully.",NULL,NULL,"O&K",NULL,'k',0,get_zc_font(font_lfont));
26217 set_last_timed_save(nullptr);
26218 }
26219
26220 save_config_file();
26221 time(&auto_save_time_start);
26222 comeback();
26223 }
26224 }
26225 }
26226
26227 void flushItemCache(bool) {}
26228 void ringcolor(bool forceDefault)
26229 {
26230 forceDefault=forceDefault;
26231 }
26232
26233 bool item_disabled(int32_t)
26234 {
26235 return false;
26236 }
26237
26238 int32_t onCmdExit()
26239 {
26240 // replaces onExit for the -large button command "Exit"
26241 close_button_quit = true;
26242 return 0;
26243 }
26244
26245 int32_t onQuickCompile()
26246 {
26247 if(do_compile_and_slots(1,false))
26248 {
26249 saved = false;
26250 InfoDialog("Quick Compile","Success!").show();
26251 }
26252 else
26253 {
26254 InfoDialog("Quick Compile","Failure!").show();
26255 }
26256 return 0;
26257 }
26258 int32_t onSmartCompile()
26259 {
26260 if(do_compile_and_slots(2,false))
26261 {
26262 saved = false;
26263 InfoDialog("Smart Compile","Success!").show();
26264 }
26265 else
26266 {
26267 InfoDialog("Smart Compile","Failure!").show();
26268 }
26269 return 0;
26270 }
26271
26272 int32_t strchrnum(char const* str, char c)
26273 {
26274 for(int32_t i=0; str[i]; ++i)
26275 {
26276 if(str[i]==c)
26277 {
26278 return i;
26279 }
26280 }
26281
26282 return -1;
26283 }
26284
26285 int32_t get_longest_line_length(FONT *f, char* str)
26286 {
26287 int32_t maxlen=0;
26288 char* tmpstr = str;
26289 char temp=0;
26290 int32_t t=0;
26291 int32_t new_t=-1;
26292 while(tmpstr[0])
26293 {
26294 t=strchrnum(tmpstr, '\n');
26295
26296 if(t==-1)
26297 {
26298 t=(int32_t)strlen(tmpstr);
26299 }
26300
26301 if((uint32_t)t!=strlen(tmpstr))
26302 {
26303 new_t=t+1;
26304 }
26305 else
26306 {
26307 new_t=-1;
26308 }
26309
26310 temp = tmpstr[t];
26311 tmpstr[t]=0;
26312 maxlen=zc_max(maxlen,text_length(f, tmpstr));
26313 tmpstr[t]=temp;
26314
26315 if(new_t!=-1)
26316 {
26317 tmpstr+=new_t;
26318 }
26319 else break;
26320 }
26321 return maxlen;
26322 }
26323
26324 int32_t count_lines(char const* str)
26325 {
26326 int32_t count=1;
26327
26328 for(word i=0; i<strlen(str); ++i)
26329 {
26330 if(str[i]=='\n')
26331 {
26332 ++count;
26333 }
26334 }
26335
26336 return count;
26337 }
26338
26339 void debug_pos(size_and_pos const& pos, int color)
26340 {
26341 if(pos.w < 1 || pos.h < 1)
26342 return;
26343 if(pos.xscale > 1 || pos.yscale > 1)
26344 {
26345 auto maxind = pos.w*pos.h;
26346 for(auto q = 0; q < maxind; ++q)
26347 {
26348 auto& sub = pos.subsquare(q);
26349 if(sub.x < 0) break;
26350 highlight_sqr(screen, color, sub, 1);
26351 }
26352 }
26353 else
26354 {
26355 if(pos.fw > -1 && pos.fh > -1)
26356 highlight_frag(screen, color, pos, 1);
26357 else highlight_sqr(screen, color, pos, 1);
26358 }
26359 }
26360
26361 void textbox_out(BITMAP* dest, FONT* font, int x, int y, int fg, int bg, char const* str, int align, size_and_pos* dims)
26362 {
26363 static size_and_pos nilsz;
26364 size_and_pos& txbox = dims ? *dims : nilsz;
26365
26366 char* kill = (char*)malloc(strlen(str)+1);
26367 char *tmpstr = kill;
26368 strcpy(tmpstr,str);
26369
26370 while(tmpstr[0] == '\n')
26371 ++tmpstr;
26372 int len = strlen(tmpstr);
26373 while(tmpstr[len-1] == '\n')
26374 tmpstr[--len] = 0;
26375
26376 txbox.x=x;
26377 txbox.y=y;
26378 int32_t lines=count_lines(tmpstr);
26379 txbox.w = 1;
26380 txbox.h = lines;
26381 txbox.xscale = get_longest_line_length(font, tmpstr);
26382 txbox.yscale = text_height(font);
26383
26384 int ax = 0; //Aligned x
26385 switch(align)
26386 {
26387 case 0: //left
26388 break;
26389 case 1: //center
26390 txbox.x -= txbox.xscale/2;
26391 ax = txbox.xscale/2;
26392 break;
26393 case 2: //right
26394 txbox.x -= txbox.xscale;
26395 ax = txbox.xscale;
26396 break;
26397 }
26398
26399 int bw = txbox.w*txbox.xscale;
26400 int bh = txbox.h*txbox.yscale;
26401 BITMAP* outbmp = create_bitmap_ex(8, bw, bh);
26402 clear_to_color(outbmp, bg);
26403
26404 char temp = 0;
26405 int32_t t=0;
26406 int32_t new_t=-1;
26407 int32_t line=0;
26408
26409 while(tmpstr[t])
26410 {
26411 t=strchrnum(tmpstr, '\n');
26412
26413 if(t==-1)
26414 t=(int32_t)strlen(tmpstr);
26415
26416 if((uint32_t)t!=strlen(tmpstr))
26417 new_t=t+1;
26418 else
26419 new_t=-1;
26420
26421 temp = tmpstr[t];
26422 tmpstr[t]=0;
26423 gui_textout_ln(outbmp, font, (ucc*)tmpstr, ax, (line*txbox.yscale), fg, -1, align);
26424 tmpstr[t]=temp;
26425 ++line;
26426
26427 if(new_t!=-1)
26428 {
26429 tmpstr+=new_t;
26430 t=0;
26431 }
26432 }
26433
26434 blit(outbmp, dest, 0, 0, txbox.x, txbox.y, bw, bh);
26435 destroy_bitmap(outbmp);
26436 free(kill);
26437 }
26438
26439 void highlight_sqr(BITMAP* dest, int color, int x, int y, int w, int h, int thick)
26440 {
26441 for(int q = 0; q < thick; ++q)
26442 {
26443 safe_rect(dest, x+q, y+q, x+w-1-q, y+h-1-q, color);
26444 }
26445 }
26446 void highlight_sqr(BITMAP* dest, int color, size_and_pos const& rec, int thick)
26447 {
26448 highlight_sqr(dest, color, rec.x, rec.y, rec.tw(), rec.th(), thick);
26449 }
26450 void highlight_frag(BITMAP* dest, int color, int x1, int y1, int w, int h, int fw, int fh, int thick)
26451 {
26452 int xc = x1+fw-1;
26453 int yc = y1+fh-1;
26454 int x2 = x1+w-1;
26455 int y2 = y1+h-1;
26456
26457 hline(dest, x1, y1, x2, color);
26458 vline(dest, x1, y1, y2, color);
26459
26460 hline(dest, x1, y2, xc, color);
26461 vline(dest, x2, y1, yc, color);
26462 hline(dest, xc, yc, x2, color);
26463 vline(dest, xc, yc, y2, color);
26464 }
26465 void highlight_frag(BITMAP* dest, int color, size_and_pos const& rec, int thick)
26466 {
26467 highlight_frag(dest, color, rec.x, rec.y, rec.tw(), rec.th(), rec.fw, rec.fh, thick);
26468 }
26469
26470 void highlight(BITMAP* dest, size_and_pos& hl)
26471 {
26472 if(hl.fw > -1 && hl.fh > -1)
26473 {
26474 highlight_frag(dest, hl.data[1], hl, hl.data[0]);
26475 }
26476 else highlight_sqr(dest, hl.data[1], hl, hl.data[0]);
26477 }
26478
26479 std::pair<int, int> get_box_text_size(char const* tipmsg, double txscale)
26480 {
26481 if(txscale < 1) txscale = 1;
26482 char* kill = (char*)malloc(strlen(tipmsg)+1);
26483 char *tmpstr = kill;
26484 strcpy(tmpstr,tipmsg);
26485
26486 while(tmpstr[0] == '\n')
26487 ++tmpstr;
26488 int len = strlen(tmpstr);
26489 while(tmpstr[len-1] == '\n')
26490 tmpstr[--len] = 0;
26491
26492 int32_t lines = count_lines(tmpstr);
26493 int txlen = get_longest_line_length(font, tmpstr);
26494 int txhei = lines*text_height(font);
26495 int tx_sclen = (txlen * txscale);
26496 int tx_schei = (txhei * txscale);
26497 int w = tx_sclen + 8 + 1;
26498 int h = tx_schei + 8 + 1;
26499 if (w > zq_screen_w)
26500 w = zq_screen_w;
26501 if (h > zq_screen_h)
26502 h = zq_screen_h;
26503 return {w, h};
26504 }
26505
26506 void draw_box(BITMAP* destbmp, size_and_pos* pos, char const* tipmsg, double txscale)
26507 {
26508 if(txscale < 1) txscale = 1;
26509 char* kill = (char*)malloc(strlen(tipmsg)+1);
26510 char *tmpstr = kill;
26511 strcpy(tmpstr,tipmsg);
26512
26513 while(tmpstr[0] == '\n')
26514 ++tmpstr;
26515 int len = strlen(tmpstr);
26516 while(tmpstr[len-1] == '\n')
26517 tmpstr[--len] = 0;
26518
26519 auto& box = *pos;
26520 clear_bitmap(destbmp);
26521
26522 int32_t lines=count_lines(tmpstr);
26523 int txlen = get_longest_line_length(font, tmpstr);
26524 int txhei = lines*text_height(font);
26525 int tx_sclen = (txlen * txscale);
26526 int tx_schei = (txhei * txscale);
26527 box.w = tx_sclen + 8 + 1;
26528 box.h = tx_schei + 8 + 1;
26529 if (box.w > zq_screen_w)
26530 box.w = zq_screen_w;
26531 if (box.h > zq_screen_h)
26532 box.h = zq_screen_h;
26533
26534 if(box.x+box.w>=zq_screen_w)
26535 {
26536 box.x=(zq_screen_w - box.w);
26537 }
26538
26539 if(box.y+box.h>=zq_screen_h)
26540 {
26541 box.y=(zq_screen_h - box.h);
26542 }
26543
26544 rectfill(destbmp, 1, 1, box.w-3, box.h-3, jwin_pal[jcTEXTBG]);
26545 rect(destbmp, 0, 0, box.w-2, box.h-2, jwin_pal[jcTEXTFG]);
26546 vline(destbmp, box.w-1, 0, box.h-1, jwin_pal[jcTEXTFG]);
26547 hline(destbmp, 1, box.h-1, box.w-2, jwin_pal[jcTEXTFG]);
26548 destbmp->line[box.h-1][0]=0;
26549 destbmp->line[0][box.w-1]=0;
26550
26551 char temp = 0;
26552 int32_t t=0;
26553 int32_t new_t=-1;
26554 int32_t line=0;
26555
26556 BITMAP* txbmp = create_bitmap_ex(8,box.w,box.h);
26557 clear_bitmap(txbmp);
26558 while(tmpstr[t])
26559 {
26560 t=strchrnum(tmpstr, '\n');
26561
26562 if(t==-1)
26563 {
26564 t=(int32_t)strlen(tmpstr);
26565 }
26566
26567 if((uint32_t)t!=strlen(tmpstr))
26568 {
26569 new_t=t+1;
26570 }
26571 else
26572 {
26573 new_t=-1;
26574 }
26575
26576 temp = tmpstr[t];
26577 tmpstr[t]=0;
26578 textprintf_ex(txbmp, font, 0, (line*text_height(font)), jwin_pal[jcTEXTFG], -1, "%s", tmpstr);
26579 tmpstr[t]=temp;
26580 ++line;
26581
26582 if(new_t!=-1)
26583 {
26584 tmpstr+=new_t;
26585 t=0;
26586 }
26587 }
26588 masked_stretch_blit(txbmp,destbmp,0,0,txlen,txhei,4,4,tx_sclen,tx_schei);
26589 destroy_bitmap(txbmp);
26590 free(kill);
26591 }
26592
26593 void update_tooltip(int32_t x, int32_t y, size_and_pos const& sqr, char const* tipmsg, double scale)
26594 {
26595 update_tooltip(x,y,sqr.x,sqr.y,sqr.w*sqr.xscale,sqr.h*sqr.yscale,tipmsg,sqr.fw,sqr.fh,scale);
26596 }
26597 void update_tooltip(int32_t x, int32_t y, int32_t tx, int32_t ty, int32_t tw, int32_t th, char const* tipmsg, int fw, int fh, double scale)
26598 {
26599 if(!EnableTooltips)
26600 {
26601 return;
26602 }
26603
26604 ttip_install(ttip_global_id, tipmsg, tx, ty, tw, th, x, y, fw, fh);
26605 }
26606
26607 void ZQ_ClearQuestPath()
26608 {
26609 zc_set_config("zquest","win_last_quest",(char const*)nullptr);
26610 strcpy(filepath,"");
26611 }
26612
26613 //FFCore
26614
26615 int32_t FFScript::GetScriptObjectUID(int32_t type)
26616 {
26617 ++script_UIDs[type];
26618 return script_UIDs[type];
26619 }
26620
26621 void FFScript::init()
26622 {
26623 for ( int32_t q = 0; q < wexLast; q++ ) warpex[q] = 0;
26624 numscriptdraws = 0;
26625 max_ff_rules = qr_MAX;
26626 temp_no_stepforward = 0;
26627 nostepforward = 0;
26628
26629 coreflags = 0;
26630 skip_ending_credits = 0;
26631 music_update_cond = 0;
26632 music_update_flags = 0;
26633 for ( int32_t q = 0; q < susptLAST; q++ ) { system_suspend[q] = 0; }
26634
26635 for ( int32_t q = 0; q < UID_TYPES; ++q ) { script_UIDs[q] = 0; }
26636 //for ( int32_t q = 0; q < 512; q++ ) FF_rules[q] = 0;
26637 int32_t usr_midi_volume = usr_digi_volume = usr_sfx_volume = usr_music_volume = usr_panstyle = 0;
26638 FF_hero_action = 0;
26639 enemy_removal_point[spriteremovalY1] = -32767;
26640 enemy_removal_point[spriteremovalY2] = 32767;
26641 enemy_removal_point[spriteremovalX1] = -32767;
26642 enemy_removal_point[spriteremovalX2] = 32767;
26643 enemy_removal_point[spriteremovalZ1] = -32767;
26644 enemy_removal_point[spriteremovalZ2] = 32767;
26645
26646 for ( int32_t q = 0; q < 4; q++ )
26647 {
26648 FF_screenbounds[q] = 0;
26649 FF_screen_dimensions[q] = 0;
26650 FF_subscreen_dimensions[q] = 0;
26651 FF_eweapon_removal_bounds[q] = 0;
26652 FF_lweapon_removal_bounds[q] = 0;
26653 }
26654 for ( int32_t q = 0; q < FFSCRIPTCLASS_CLOCKS; q++ )
26655 {
26656 FF_clocks[q] = 0;
26657 }
26658 for ( int32_t q = 0; q < SCRIPT_DRAWING_RULES; q++ )
26659 {
26660 ScriptDrawingRules[q] = 0;
26661 }
26662 for ( int32_t q = 0; q < NUM_USER_MIDI_OVERRIDES; q++ )
26663 {
26664 FF_UserMidis[q] = 0;
26665 }
26666 subscreen_scroll_speed = 0; //make a define for a default and read quest override! -Z
26667 kb_typing_mode = false;
26668 initIncludePaths();
26669 for(int32_t q = 0; q < 7; ++q)
26670 {
26671 tempScreens[q] = NULL;
26672 ScrollingScreens[q] = NULL;
26673 }
26674 }
26675
26676 void FFScript::updateIncludePaths()
26677 {
26678 includePaths.clear();
26679 int32_t pos = 0; int32_t pathnumber = 0;
26680 for ( int32_t q = 0; includePathString[pos]; ++q )
26681 {
26682 int32_t dest = 0;
26683 char buf[2048] = {0};
26684 while(includePathString[pos] != ';' && includePathString[pos])
26685 {
26686 buf[dest] = includePathString[pos];
26687 ++pos;
26688 ++dest;
26689 }
26690 ++pos;
26691 string str(buf);
26692 includePaths.push_back(str);
26693 }
26694 }
26695
26696 void FFScript::initIncludePaths()
26697 {
26698 memset(includePathString,0,sizeof(includePathString));
26699 FILE* f = fopen("includepaths.txt", "r");
26700 if(f)
26701 {
26702 int32_t pos = 0;
26703 int32_t c;
26704 do
26705 {
26706 c = fgetc(f);
26707 if(c!=EOF)
26708 includePathString[pos++] = c;
26709 }
26710 while(c!=EOF && pos<MAX_INCLUDE_PATH_CHARS);
26711 if(pos<MAX_INCLUDE_PATH_CHARS)
26712 includePathString[pos] = '\0';
26713 includePathString[MAX_INCLUDE_PATH_CHARS-1] = '\0';
26714 fclose(f);
26715 }
26716 else strcpy(includePathString, "include/;headers/;scripts/;");
26717 al_trace("Full path string is: ");
26718 safe_al_trace(includePathString);
26719 al_trace("\n");
26720 updateIncludePaths();
26721
26722 for ( size_t q = 0; q < includePaths.size(); ++q )
26723 {
26724 al_trace("Include path %zu: ",q);
26725 safe_al_trace(includePaths.at(q).c_str());
26726 al_trace("\n");
26727 }
26728 }
26729
26730 int32_t FFScript::getQRBit(int32_t rule)
26731 {
26732 return ( get_qr(rule) ? 1 : 0 );
26733 }
26734
26735 int32_t FFScript::getTime(int32_t type)
26736 {
26737 //struct tm *tm_struct = localtime(time(NULL));
26738 struct tm * tm_struct;
26739 time_t rawtime;
26740 time (&rawtime);
26741 tm_struct = localtime (&rawtime);
26742
26743 switch(type)
26744 {
26745 case curyear:
26746 {
26747 int32_t year = tm_struct->tm_year + 1900; /* year */
26748 //year format starts at 1900, so we add it to the return
26749 return year;
26750
26751 }
26752 case curmonth:
26753 {
26754 int32_t month = tm_struct->tm_mon +1; /* month */
26755 //Months start at 0, but we want 1->12
26756 return month;
26757 }
26758 case curday_month:
26759 {
26760 int32_t day_month = tm_struct->tm_mday; /* day of the month */
26761 return day_month;
26762 }
26763 case curday_week:
26764 {
26765 int32_t day_week = tm_struct->tm_wday; /* day of the week */
26766 return day_week;
26767 }
26768 case curhour:
26769 {
26770 int32_t hour = tm_struct->tm_hour; /* hours */
26771 return hour;
26772 }
26773 case curminute:
26774 {
26775 int32_t minutes = tm_struct->tm_min; /* minutes */
26776 return minutes;
26777 }
26778 case cursecond:
26779 {
26780 int32_t secs = tm_struct->tm_sec; /* seconds */
26781 return secs;
26782 }
26783 case curdayyear:
26784 {
26785 int32_t day_year = tm_struct->tm_yday; /* day in the year */
26786 return day_year;
26787 }
26788 case curDST:
26789 {
26790 int32_t isDST = tm_struct->tm_isdst; /* daylight saving time */
26791 return isDST;
26792 }
26793 default: return -1;
26794
26795 }
26796 }
26797
26798 extern const char *itemclass_help_string_defaults[itype_max];
26799 //ZModule Functions
26800
26801
26802
26803 /* end */
26804
26805 16384 int32_t FFScript::getQuestHeaderInfo(int32_t type)
26806 {
26807 16384 return quest_format[type];
26808 }
26809
26810 bool isSideViewGravity(int32_t t)
26811 {
26812 return (Map.CurrScr()->flags7&fSIDEVIEW) != 0;
26813 }
26814
26815
26816
26817
26818 void FFScript::ZScriptConsole(bool open)
26819 {
26820
26821
26822 #ifdef _WIN32
26823 if ( console_is_open )
26824 {
26825 zscript_coloured_console.Create("ZQuest Classic Logging Console", 600, 200);
26826 zscript_coloured_console.cls(CConsoleLoggerEx::COLOR_BACKGROUND_BLACK);
26827 zscript_coloured_console.gotoxy(0,0);
26828 zscript_coloured_console.cprintf( CConsoleLoggerEx::COLOR_BLUE | CConsoleLoggerEx::COLOR_INTENSITY |
26829 CConsoleLoggerEx::COLOR_BACKGROUND_BLACK,"ZQuest Classic Logging Console\n");
26830 }
26831 else
26832 {
26833 //close
26834 zscript_coloured_console.Close();
26835 }
26836 #endif
26837 }
26838
26839 template <typename ...Params>
26840 void FFScript::ZScriptConsole(int32_t attributes,const char *format, Params&&... params)
26841 {
26842 #ifdef _WIN32
26843 initConsole();
26844 zscript_coloured_console.cprintf( attributes, format, std::forward<Params>(params)... );
26845 #endif
26846 }
26847
26848 int32_t getpitfall(int32_t x, int32_t y){return 0;}
26849
26850 int32_t iswaterexzq(int32_t combo, int32_t map, int32_t screen, int32_t layer, int32_t x, int32_t y, bool secrets, bool fullcheck, bool LayerCheck){return 0;}
26851
26852 int32_t MAPCOMBOzq(int32_t x, int32_t y){return 0;}
26853
26854 bool update_hw_pal = false;
26855 void update_hw_screen()
26856 {
26857 if (is_headless())
26858 return;
26859
26860 framecnt++;
26861
26862 zc_process_display_events();
26863 if (update_hw_pal)
26864 {
26865 zc_set_palette(RAMpal);
26866 update_hw_pal = false;
26867 }
26868
26869 render_timer_wait();
26870 render_zq();
26871 }
26872
26873 bool checkCost(int32_t ctr, int32_t amnt)
26874 {
26875 if(!game) return true;
26876 if(amnt <= 0) return true;
26877 switch (ctr)
26878 {
26879 case crMONEY: //rupees
26880 {
26881 if ( current_item_power(itype_wallet) ) return true;
26882 break;
26883 }
26884 case crMAGIC: //magic
26885 {
26886 if (get_qr(qr_ENABLEMAGIC))
26887 {
26888 return (((current_item_power(itype_magicring) > 0)
26889 ? game->get_maxmagic()
26890 : game->get_magic()+game->get_dmagic())>=amnt*game->get_magicdrainrate());
26891 }
26892 return true;
26893 }
26894 case crARROWS:
26895 {
26896 if(current_item_power(itype_quiver))
26897 return true;
26898 if(!get_qr(qr_TRUEARROWS))
26899 return checkCost(crMONEY, amnt);
26900 break;
26901 }
26902 case crBOMBS:
26903 {
26904 if(current_item_power(itype_bombbag))
26905 return true;
26906 break;
26907 }
26908 case crSBOMBS:
26909 {
26910 if(current_item_power(itype_bombbag)
26911 && itemsbuf[current_item_id(itype_bombbag)].flags & item_flag1)
26912 return true;
26913 break;
26914 }
26915 }
26916 return (game->get_counter(ctr)+game->get_dcounter(ctr)>=amnt);
26917 }
26918 bool checkmagiccost(int32_t itemid, bool checkTime)
26919 {
26920 if(itemid < 0)
26921 {
26922 return false;
26923 }
26924 itemdata const& id = itemsbuf[itemid];
26925 return checkCost(id.cost_counter[0], id.cost_amount[0])
26926 && checkCost(id.cost_counter[1], id.cost_amount[1]);
26927 }
26928
26929 void payCost(int32_t ctr, int32_t amnt, int32_t tmr, bool ignoreTimer)
26930 {
26931 return;
26932 }
26933 void paymagiccost(int32_t itemid, bool ignoreTimer, bool onlyTimer)
26934 {
26935 return;
26936 }
26937
26938 void enter_sys_pal(){}
26939 void exit_sys_pal(){}
26940
26941 void replay_step_comment(std::string comment) {}
26942 bool replay_is_active() {return false;}
26943 bool replay_is_replaying() {return false;}
26944 bool replay_version_check(int min, int max) {return false;}
26945 bool replay_is_debug() {return false;}
26946 int32_t item::run_script(int32_t mode){return 0;};
26947 ffcdata* slopes_getFFC(int index)
26948 {
26949 return nullptr;
26950 }
26951
26952 #ifdef __EMSCRIPTEN__
26953 extern "C" void open_test_mode()
26954 {
26955 int dmap = -1;
26956 int32_t pal = Map.getcolor();
26957 for(auto q = 0; q < MAXDMAPS; ++q)
26958 {
26959 if(DMaps[q].map == Map.getCurrMap())
26960 {
26961 if(pal == DMaps[q].color)
26962 {
26963 dmap = q;
26964 break;
26965 }
26966 if(dmap < 0)
26967 dmap = q;
26968 }
26969 }
26970 if(dmap < 0) dmap = 0;
26971
26972 em_open_test_mode(filepath, dmap, Map.getCurrScr(), -1);
26973 }
26974
26975 extern "C" void get_shareable_url()
26976 {
26977 EM_ASM({
26978 ZC.setShareableUrl({open: UTF8ToString($0), map: $1, screen: $2});
26979 }, filepath, Map.getCurrMap(), Map.getCurrScr());
26980 }
26981 #endif
26982